Skip to content

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

Treat all column change as incompatible

天舟51f66c484316
diff --git a/plugin/advisor/mysql/mysql_migration_compatibility_advisor.go b/plugin/advisor/mysql/mysql_migration_compatibility_advisor.go
index 2f03ef9787..6747b3c9ae 100644
--- a/plugin/advisor/mysql/mysql_migration_compatibility_advisor.go
+++ b/plugin/advisor/mysql/mysql_migration_compatibility_advisor.go
@@ -115,6 +115,16 @@ func (v *compatibilityChecker) Enter(in ast.Node) (ast.Node, bool) {
goto END
}
}
+
+ // MODIFY COLUMN / CHANGE COLUMN
+ // Due to the limitation that we don't know the current data type of the column before the change,
+ // so we treat all as incompatible. This generates false positive when:
+ // 1. Change to a compatible data type such as INT to BIGINT
+ // 2. Change property like comment, change it to NULL
+ if spec.Tp == ast.AlterTableModifyColumn || spec.Tp == ast.AlterTableChangeColumn {
+ compatible = false
+ goto END
+ }
}
}
// ALTER VIEW TBD: https://github.com/pingcap/parser/pull/1252
diff --git a/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go b/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go
index f8a8a8d22b..e59a93399f 100644
--- a/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go
+++ b/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go
@@ -251,3 +251,60 @@ func TestAlterTable(t *testing.T) {
runTests(t, tests)
}
+
+func TestAlterTableChangeColumnType(t *testing.T) {
+ tests := []test{
+ {
+ statement: "ALTER TABLE t1 CHANGE f1 f2 TEXT",
+ want: []advisor.Advice{
+ {
+ Status: advisor.Warn,
+ Title: "Incompatible migration",
+ Content: "ALTER TABLE t1 CHANGE f1 f2 TEXT is backward incompatible",
+ },
+ },
+ },
+ {
+ statement: "ALTER TABLE t1 MODIFY f1 TEXT",
+ want: []advisor.Advice{
+ {
+ Status: advisor.Warn,
+ Title: "Incompatible migration",
+ Content: "ALTER TABLE t1 MODIFY f1 TEXT is backward incompatible",
+ },
+ },
+ },
+ {
+ statement: "ALTER TABLE t1 MODIFY f1 TEXT NULL",
+ want: []advisor.Advice{
+ {
+ Status: advisor.Warn,
+ Title: "Incompatible migration",
+ Content: "ALTER TABLE t1 MODIFY f1 TEXT NULL is backward incompatible",
+ },
+ },
+ },
+ {
+ statement: "ALTER TABLE t1 MODIFY f1 TEXT NOT NULL",
+ want: []advisor.Advice{
+ {
+ Status: advisor.Warn,
+ Title: "Incompatible migration",
+ Content: "ALTER TABLE t1 MODIFY f1 TEXT NOT NULL is backward incompatible",
+ },
+ },
+ },
+ {
+ statement: "ALTER TABLE t1 MODIFY f1 TEXT COMMENT 'bla'",
+ want: []advisor.Advice{
+ {
+ Status: advisor.Warn,
+ Title: "Incompatible migration",
+ Content: "ALTER TABLE t1 MODIFY f1 TEXT COMMENT 'bla' is backward incompatible",
+ },
+ },
+ },
+ }
+
+ runTests(t, tests)
+}