diff --git a/sources/common/toddl.go b/sources/common/toddl.go index c8f0adfbc..28c37c23c 100644 --- a/sources/common/toddl.go +++ b/sources/common/toddl.go @@ -294,7 +294,6 @@ func (ss *SchemaToSpannerImpl) SchemaToSpannerDDLHelper(conv *internal.Conv, tod Comment: comment, Id: srcTable.Id, } - return nil } @@ -360,9 +359,10 @@ func cvtCheckConstraint(conv *internal.Conv, srcKeys []schema.CheckConstraint) [ for _, cc := range srcKeys { spcc = append(spcc, ddl.CheckConstraint{ - Id: cc.Id, - Name: internal.ToSpannerCheckConstraintName(conv, cc.Name), - Expr: cc.Expr, + Id: cc.Id, + Name: internal.ToSpannerCheckConstraintName(conv, cc.Name), + Expr: cc.Expr, + ExprId: cc.ExprId, }) } return spcc diff --git a/sources/common/toddl_test.go b/sources/common/toddl_test.go index 6a98b8ca9..43d133d1f 100644 --- a/sources/common/toddl_test.go +++ b/sources/common/toddl_test.go @@ -434,14 +434,22 @@ func Test_cvtCheckContraint(t *testing.T) { conv := internal.MakeConv() srcSchema := []schema.CheckConstraint{ { - Id: "cc1", - Name: "check_1", - Expr: "age > 0", + Id: "cc1", + Name: "check_1", + Expr: "age > 0", + ExprId: "expr1", }, { - Id: "cc2", - Name: "check_2", - Expr: "age < 99", + Id: "cc2", + Name: "check_2", + Expr: "age < 99", + ExprId: "expr2", + }, + { + Id: "cc3", + Name: "@invalid_name", // incompatabile name + Expr: "age != 0", + ExprId: "expr3", }, { Id: "cc3", @@ -451,14 +459,22 @@ func Test_cvtCheckContraint(t *testing.T) { } spSchema := []ddl.CheckConstraint{ { - Id: "cc1", - Name: "check_1", - Expr: "age > 0", + Id: "cc1", + Name: "check_1", + Expr: "age > 0", + ExprId: "expr1", + }, + { + Id: "cc2", + Name: "check_2", + Expr: "age < 99", + ExprId: "expr2", }, { - Id: "cc2", - Name: "check_2", - Expr: "age < 99", + Id: "cc3", + Name: "Ainvalid_name", + Expr: "age != 0", + ExprId: "expr3", }, { Id: "cc3", diff --git a/sources/mysql/infoschema.go b/sources/mysql/infoschema.go index 0769b34b7..7f2992ed3 100644 --- a/sources/mysql/infoschema.go +++ b/sources/mysql/infoschema.go @@ -337,7 +337,7 @@ func (isi InfoSchemaImpl) processRow( // Case added to handle check constraints case "CHECK": checkClause = collationRegex.ReplaceAllString(checkClause, "") - *checkKeys = append(*checkKeys, schema.CheckConstraint{Name: constraintName, Expr: checkClause, Id: internal.GenerateCheckConstrainstId()}) + *checkKeys = append(*checkKeys, schema.CheckConstraint{Name: constraintName, Expr: checkClause, ExprId: internal.GenerateCheckConstrainstExprId(), Id: internal.GenerateCheckConstrainstId()}) default: m[col] = append(m[col], constraintType) } diff --git a/webv2/api/schema.go b/webv2/api/schema.go index 6f535a250..0c4ac3a2c 100644 --- a/webv2/api/schema.go +++ b/webv2/api/schema.go @@ -531,6 +531,7 @@ func UpdateCheckConstraint(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(convm) } +// findColId based on constraint condition it will return colId. func findColId(colDefs map[string]ddl.ColumnDef, condition string) string { for _, colDef := range colDefs { if strings.Contains(condition, colDef.Name) {