Skip to content

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

chore: move setting foreign key checks (#12779)

Danny Xu8604fbb5e0c7
diff --git a/backend/plugin/parser/mysql/differ.go b/backend/plugin/parser/mysql/differ.go
index eb02f7d9b9..93e8f55316 100644
--- a/backend/plugin/parser/mysql/differ.go
+++ b/backend/plugin/parser/mysql/differ.go
@@ -21,11 +21,6 @@ func init() {
base.RegisterSchemaDiffFunc(storepb.Engine_OCEANBASE, SchemaDiff)
}
-const (
- disableFKCheckStmt string = "SET FOREIGN_KEY_CHECKS=0;\n\n"
- enableFKCheckStmt string = "SET FOREIGN_KEY_CHECKS=1;\n"
-)
-
// SchemaDiffer is the parser for MySQL dialect.
type SchemaDiffer struct {
}
@@ -839,11 +834,7 @@ func (diff *diffNode) deparse() (string, error) {
return "", err
}
- text := buf.String()
- if len(text) > 0 {
- return fmt.Sprintf("%s%s%s", disableFKCheckStmt, buf.String(), enableFKCheckStmt), nil
- }
- return "", nil
+ return buf.String(), nil
}
func sortAndWriteAlertTableOptionList(buf *strings.Builder, tableOptions []*tableOptionDef) error {
diff --git a/backend/plugin/parser/mysql/differ_test.go b/backend/plugin/parser/mysql/differ_test.go
index b722dfa7c0..38ff6703f9 100644
--- a/backend/plugin/parser/mysql/differ_test.go
+++ b/backend/plugin/parser/mysql/differ_test.go
@@ -33,12 +33,6 @@ func runDifferTest(t *testing.T, file string, record bool) {
for i, test := range tests {
diff, err := SchemaDiff(base.DiffContext{IgnoreCaseSensitive: false, StrictMode: true}, test.OldSchema, test.NewSchema)
require.NoErrorf(t, err, "Test Cases[%02d] Failed", i+1)
- if len(diff) > 0 {
- require.Equalf(t, disableFKCheckStmt, diff[:len(disableFKCheckStmt)], "Test Cases[%02d] Failed", i+1)
- diff = diff[len(disableFKCheckStmt):]
- require.Equalf(t, enableFKCheckStmt, diff[len(diff)-len(enableFKCheckStmt):], "Test Cases[%02d] Failed", i+1)
- diff = diff[:len(diff)-len(enableFKCheckStmt)]
- }
if record {
tests[i].Diff = diff
} else {
diff --git a/backend/plugin/parser/tidb/differ.go b/backend/plugin/parser/tidb/differ.go
index 7ff6bba1e4..899ff68e74 100644
--- a/backend/plugin/parser/tidb/differ.go
+++ b/backend/plugin/parser/tidb/differ.go
@@ -28,11 +28,6 @@ func init() {
base.RegisterSchemaDiffFunc(storepb.Engine_TIDB, SchemaDiff)
}
-const (
- disableFKCheckStmt string = "SET FOREIGN_KEY_CHECKS=0;\n\n"
- enableFKCheckStmt string = "SET FOREIGN_KEY_CHECKS=1;\n"
-)
-
// diffNode defines different modification types as the safe change order.
// The safe change order means we can change them with no dependency conflicts as this order.
type diffNode struct {
@@ -460,11 +455,7 @@ func (diff *diffNode) deparse() (string, error) {
return "", err
}
- text := buf.String()
- if len(text) > 0 {
- return fmt.Sprintf("%s%s%s", disableFKCheckStmt, buf.String(), enableFKCheckStmt), nil
- }
- return "", nil
+ return buf.String(), nil
}
// constraintMap returns a map of constraint name to constraint.
diff --git a/backend/plugin/parser/tidb/differ_test.go b/backend/plugin/parser/tidb/differ_test.go
index 3e8dbe180d..c58c32e000 100644
--- a/backend/plugin/parser/tidb/differ_test.go
+++ b/backend/plugin/parser/tidb/differ_test.go
@@ -22,12 +22,6 @@ func testDiffWithoutDisableForeignKeyCheck(t *testing.T, testCases []testCase) {
StrictMode: true,
}, test.old, test.new)
a.NoError(err)
- if len(out) > 0 {
- a.Equal(disableFKCheckStmt, out[:len(disableFKCheckStmt)])
- out = out[len(disableFKCheckStmt):]
- a.Equal(enableFKCheckStmt, out[len(out)-len(enableFKCheckStmt):])
- out = out[:len(out)-len(enableFKCheckStmt)]
- }
a.Equalf(test.want, out, "old: %s\nnew: %s\n", test.old, test.new)
}
}