Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(catalog): check the ON UPDATE column type (#3052)

rebelice58c638b14a31
diff --git a/plugin/advisor/catalog/walk_through.go b/plugin/advisor/catalog/walk_through.go
index 2b7cf24b96..826dbd1402 100644
--- a/plugin/advisor/catalog/walk_through.go
+++ b/plugin/advisor/catalog/walk_through.go
@@ -61,6 +61,8 @@ const (
ErrorTypeDropAllColumns = 403
// ErrorTypeAutoIncrementExists is the error that auto_increment exists.
ErrorTypeAutoIncrementExists = 404
+ // ErrorTypeOnUpdateColumnNotDatetimeOrTimestamp is the error that the ON UPDATE column is not datetime or timestamp.
+ ErrorTypeOnUpdateColumnNotDatetimeOrTimestamp = 405
// 501 ~ 599 index error type.
@@ -1207,6 +1209,12 @@ func (t *TableState) createColumn(ctx *FinderContext, column *tidbast.ColumnDef,
col.nullable = newTruePointer()
case tidbast.ColumnOptionOnUpdate:
// we do not deal with ON UPDATE
+ if column.Tp.GetType() != mysql.TypeDatetime && column.Tp.GetType() != mysql.TypeTimestamp {
+ return &WalkThroughError{
+ Type: ErrorTypeOnUpdateColumnNotDatetimeOrTimestamp,
+ Content: fmt.Sprintf("Column `%s` use ON UPDATE but is not DATETIME or TIMESTAMP", col.name),
+ }
+ }
case tidbast.ColumnOptionComment:
comment, err := restoreNode(option.Expr, format.RestoreStringWithoutCharset)
if err != nil {
diff --git a/plugin/advisor/catalog/walk_through_test.go b/plugin/advisor/catalog/walk_through_test.go
index 35961130bf..bd6ce678f2 100644
--- a/plugin/advisor/catalog/walk_through_test.go
+++ b/plugin/advisor/catalog/walk_through_test.go
@@ -23,6 +23,20 @@ var (
func TestWalkThrough(t *testing.T) {
tests := []testData{
+ {
+ origin: &Database{
+ Name: "test",
+ DbType: db.MySQL,
+ },
+ statement: `
+ CREATE TABLE t(a int ON UPDATE NOW())
+ `,
+ err: &WalkThroughError{
+ Type: ErrorTypeOnUpdateColumnNotDatetimeOrTimestamp,
+ Content: "Column `a` use ON UPDATE but is not DATETIME or TIMESTAMP",
+ Line: 2,
+ },
+ },
{
origin: &Database{
Name: "test",