Skip to content

Commit

Permalink
schemadiff: only compare column collations if of textual type (vite…
Browse files Browse the repository at this point in the history
…ssio#16138)

Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach authored Jun 12, 2024
1 parent 3f2d096 commit 8d69437
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions go/vt/schemadiff/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,13 @@ func colTypeEqualForForeignKey(env *Environment, ct, pt *sqlparser.TableSpec, ch
}

func colCollationEqualForForeignKey(env *Environment, ct, pt *sqlparser.TableSpec, child, parent *sqlparser.ColumnType) bool {
isTextual := func(col *sqlparser.ColumnType) bool {
return charsetTypes[strings.ToLower(col.Type)]
}
if !isTextual(child) || !isTextual(parent) {
// irrelevant if columns are not textual
return true
}
return *colCollation(env, ct, child) == *colCollation(env, pt, parent)
}

Expand Down
22 changes: 22 additions & 0 deletions go/vt/schemadiff/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,28 @@ func TestInvalidSchema(t *testing.T) {
create table t13 (id int primary key, i int, key i_idx (i), constraint f1307 foreign key (i) references t11 (i));
`,
},
{
schema: `
CREATE TABLE t1 (id int NOT NULL AUTO_INCREMENT, primary key (id));
CREATE TABLE t2 (
id int NOT NULL AUTO_INCREMENT,
t1id int NOT NULL,
primary key (id),
CONSTRAINT fk1_en9z857fmvhhyrzb1p7lr751o FOREIGN KEY (t1id) REFERENCES t1 (id) ON DELETE CASCADE
);
`,
},
{
schema: `
CREATE TABLE t1 (id int NOT NULL AUTO_INCREMENT, primary key (id)) CHARSET utf8mb4, COLLATE utf8mb4_unicode_ci;
CREATE TABLE t2 (
id int NOT NULL AUTO_INCREMENT,
t1id int NOT NULL,
primary key (id),
CONSTRAINT fk1_en9z857fmvhhyrzb1p7lr751o FOREIGN KEY (t1id) REFERENCES t1 (id) ON DELETE CASCADE
) CHARSET utf8mb4, COLLATE utf8mb4_0900_ai_ci;
`,
},
{
schema: "create table t11 (id int primary key, i int, key ix(i), constraint f11 foreign key (i) references t11(id2) on delete restrict)",
expectErr: &InvalidReferencedColumnInForeignKeyConstraintError{Table: "t11", Constraint: "f11", ReferencedTable: "t11", ReferencedColumn: "id2"},
Expand Down

0 comments on commit 8d69437

Please sign in to comment.