Merge remote-tracking branch 'origin/main' into aaron/cluster-replication-heartbeats

This commit is contained in:
Aaron Son
2023-05-15 14:00:34 -07:00
5 changed files with 19 additions and 4 deletions

View File

@@ -3393,7 +3393,7 @@ var PatchTableFunctionScriptTests = []queries.ScriptTest{
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT statement_order, table_name, diff_type, statement FROM dolt_patch('HEAD', 'WORKING')",
Expected: []sql.Row{{1, "foo", "schema", "CREATE TABLE `foo` (\n `pk` int NOT NULL,\n `c1` int,\n PRIMARY KEY (`pk`),\n CONSTRAINT `chk_eq3jn5ra` CHECK ((c1 > 3))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"}},
Expected: []sql.Row{{1, "foo", "schema", "CREATE TABLE `foo` (\n `pk` int NOT NULL,\n `c1` int,\n PRIMARY KEY (`pk`),\n CONSTRAINT `foo_chk_eq3jn5ra` CHECK ((c1 > 3))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;"}},
},
},
},

View File

@@ -2541,7 +2541,7 @@ func (t *AlterableDoltTable) generateCheckName(ctx *sql.Context, check *sql.Chec
bb.Write([]byte(check.CheckExpression))
hash := hash.Of(bb.Bytes())
hashedName := fmt.Sprintf("chk_%s", hash.String()[:8])
hashedName := fmt.Sprintf("%s_chk_%s", t.tableName, hash.String()[:8])
name := hashedName
var i int

View File

@@ -332,7 +332,7 @@ SQL
[[ "$output" =~ "+ \`b\` tinyint NOT NULL," ]] || false
[[ "$output" =~ "+ \`c\` varchar(10)," ]] || false
[[ "$output" =~ "+ PRIMARY KEY (\`a\`)," ]] || false
[[ "$output" =~ "+ CONSTRAINT \`chk_vk8cbuqc\` CHECK ((\`b\` > 0))" ]] || false
[[ "$output" =~ "+ CONSTRAINT \`test_chk_vk8cbuqc\` CHECK ((\`b\` > 0))" ]] || false
}
@test "drop-create: default changes" {

View File

@@ -81,7 +81,7 @@ SQL
# check information_schema.CHECK_CONSTRAINTS table
run dolt sql -q "select constraint_catalog, constraint_name, check_clause from information_schema.CHECK_CONSTRAINTS;" -r csv
[[ "$output" =~ "def,chk_eq3jn5ra,(c1 > 3)" ]] || false
[[ "$output" =~ "def,foo_chk_eq3jn5ra,(c1 > 3)" ]] || false
}
@test "sql-check-constraints: check constraints survive renaming a column" {

View File

@@ -776,3 +776,18 @@ SQL
dolt sql -q "INSERT INTO budgets VALUES (UUID());"
dolt sql -q "INSERT INTO budgets2 VALUES (UUID());"
}
@test "sql-create-tables: tables should not reuse constraint names" {
run dolt sql -r csv <<SQL
CREATE TABLE t1 (
pk int PRIMARY KEY,
val int CHECK (val > 0)
);
CREATE TABLE t2 LIKE t1;
SELECT count(CONSTRAINT_NAME), count(distinct CONSTRAINT_NAME) FROM information_schema.table_constraints WHERE CONSTRAINT_TYPE="CHECK";
SQL
[ "$status" -eq 0 ]
[[ "$output" =~ "2,2" ]] || false
}