mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-12 02:58:53 -06:00
Match quoted and unquoted check definitions during merge. (#9437)
This commit is contained in:
@@ -63,7 +63,10 @@ func ResolveCheckExpression(ctx *sql.Context, tableName string, sch schema.Schem
|
||||
}
|
||||
|
||||
for _, check := range ct.Checks() {
|
||||
if stripTableNamesFromExpression(check.Expr).String() == checkExpr {
|
||||
// Check definitions created before v1.55.3 may not have backquotes around identifiers
|
||||
quotedExpr := stripTableNamesFromExpression(check.Expr, true).String()
|
||||
unquotedExpr := stripTableNamesFromExpression(check.Expr, false).String()
|
||||
if quotedExpr == checkExpr || unquotedExpr == checkExpr {
|
||||
return check.Expr, nil
|
||||
}
|
||||
}
|
||||
@@ -71,10 +74,10 @@ func ResolveCheckExpression(ctx *sql.Context, tableName string, sch schema.Schem
|
||||
return nil, fmt.Errorf("unable to find check expression")
|
||||
}
|
||||
|
||||
func stripTableNamesFromExpression(expr sql.Expression) sql.Expression {
|
||||
func stripTableNamesFromExpression(expr sql.Expression, quoted bool) sql.Expression {
|
||||
e, _, _ := transform.Expr(expr, func(e sql.Expression) (sql.Expression, transform.TreeIdentity, error) {
|
||||
if col, ok := e.(*expression.GetField); ok {
|
||||
return col.WithTable("").WithQuotedNames(sql.GlobalSchemaFormatter, true), transform.NewTree, nil
|
||||
return col.WithTable("").WithQuotedNames(sql.GlobalSchemaFormatter, quoted), transform.NewTree, nil
|
||||
}
|
||||
return e, transform.SameTree, nil
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
v1.55.3
|
||||
v1.7.0
|
||||
v1.6.0
|
||||
v1.5.0
|
||||
|
||||
@@ -206,3 +206,8 @@ EOF
|
||||
|
||||
dolt sql -q 'drop table abc2'
|
||||
}
|
||||
|
||||
@test "dolt merge with check constraints" {
|
||||
run dolt merge check_merge
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@@ -36,6 +36,11 @@ CREATE TABLE big (
|
||||
pk int PRIMARY KEY,
|
||||
str longtext
|
||||
);
|
||||
|
||||
CREATE TABLE def (
|
||||
i INT check (i > 0)
|
||||
);
|
||||
INSERT INTO def VALUES (1), (2), (3);
|
||||
SQL
|
||||
dolt sql < "../../test_files/big_table.sql" # inserts 1K rows to `big`
|
||||
dolt add .
|
||||
@@ -54,6 +59,8 @@ SQL
|
||||
dolt add .
|
||||
dolt commit -m "made changes to $DEFAULT_BRANCH"
|
||||
|
||||
dolt branch check_merge
|
||||
|
||||
dolt checkout other
|
||||
dolt sql <<SQL
|
||||
DELETE FROM abc WHERE pk=2;
|
||||
@@ -66,6 +73,13 @@ SQL
|
||||
dolt add .
|
||||
dolt commit -m "made changes to other"
|
||||
|
||||
dolt checkout check_merge
|
||||
dolt sql <<SQL
|
||||
INSERT INTO def VALUES (5), (6), (7);
|
||||
SQL
|
||||
dolt add .
|
||||
dolt commit -m "made changes to check_merge"
|
||||
|
||||
dolt checkout "$DEFAULT_BRANCH"
|
||||
dolt table export abc abc.csv
|
||||
dolt schema export abc abc_schema.json
|
||||
|
||||
Reference in New Issue
Block a user