Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: add constraint name check for SDL format (#5128)
rebelice171ac1593795
diff --git a/backend/plugin/parser/transform/mysql/transform.go b/backend/plugin/parser/transform/mysql/transform.goindex 0ab8eae63c..5340c1daaa 100644--- a/backend/plugin/parser/transform/mysql/transform.go+++ b/backend/plugin/parser/transform/mysql/transform.go@@ -375,6 +375,9 @@ func (*SchemaTransformer) Check(schema string) (int, error) {case ast.ConstraintFulltext:return stmt.LastLine, errors.Errorf("The fulltext constraint in CREATE TABLE statements is invalid SDL format. Please use CREATE FULLTEXT INDEX statements, such as \"CREATE UNIQUE INDEX fdx_t_id ON t(id);\"")case ast.ConstraintCheck, ast.ConstraintForeignKey:+ if constraint.Name == "" {+ return stmt.LastLine, errors.Errorf("The constraint name is required for SDL format")+ }}}if node.Partition != nil {diff --git a/backend/plugin/parser/transform/mysql/transform_test.go b/backend/plugin/parser/transform/mysql/transform_test.goindex 5d996d505a..463ea048d5 100644--- a/backend/plugin/parser/transform/mysql/transform_test.go+++ b/backend/plugin/parser/transform/mysql/transform_test.go@@ -69,3 +69,26 @@ func TestNormalize(t *testing.T) {a.NoError(err)a.Equal(want, got)}++func TestCheck(t *testing.T) {+ type testData struct {+ input string+ err string+ }+ tests := []testData{+ {+ input: `create table t(a int, FOREIGN KEY (a) references t1(a));`,+ err: "The constraint name is required for SDL format",+ },+ {+ input: `create table t(a int, CHECK (a > 0));`,+ err: "The constraint name is required for SDL format",+ },+ }+ a := require.New(t)+ mysqlTransformer := &SchemaTransformer{}+ for _, test := range tests {+ _, err := mysqlTransformer.Check(test.input)+ a.Equal(test.err, err.Error())+ }+}