Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions go/libraries/doltcore/sqle/expranalysis/expranalysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,21 @@ 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
}
}

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
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
v1.55.3
v1.7.0
v1.6.0
v1.5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
14 changes: 14 additions & 0 deletions integration-tests/compatibility/test_files/setup_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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;
Expand All @@ -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
Expand Down
Loading