-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
schemadiff: fix missing DROP CONSTRAINT
in duplicate/redundant constraints scenario.
#14387
Changes from all commits
8736b50
1370607
cb89a48
024e542
af629cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -607,6 +607,14 @@ func TestCreateTableDiff(t *testing.T) { | |
cdiff: "ALTER TABLE `t1` DROP CHECK `check3`", | ||
constraint: ConstraintNamesIgnoreAll, | ||
}, | ||
{ | ||
name: "check constraints, remove duplicate", | ||
from: "create table t1 (id int primary key, i int, constraint `chk_123abc` CHECK ((`i` > 2)), constraint `check3` CHECK ((`i` > 2)), constraint `chk_789def` CHECK ((`i` < 5)))", | ||
to: "create table t2 (id int primary key, i int, constraint `chk_123abc` CHECK ((`i` > 2)), constraint `chk_789def` CHECK ((`i` < 5)))", | ||
diff: "alter table t1 drop check check3", | ||
cdiff: "ALTER TABLE `t1` DROP CHECK `check3`", | ||
constraint: ConstraintNamesIgnoreAll, | ||
}, | ||
{ | ||
name: "check constraints, remove, ignore vitess, no match", | ||
from: "create table t1 (id int primary key, i int, constraint `chk_123abc` CHECK ((`i` > 2)), constraint `check3` CHECK ((`i` != 3)), constraint `chk_789def` CHECK ((`i` < 5)))", | ||
|
@@ -658,6 +666,37 @@ func TestCreateTableDiff(t *testing.T) { | |
from: "create table t1 (id int primary key, i int, constraint f foreign key (i) references parent(id) on delete cascade)", | ||
to: "create table t2 (id int primary key, i int, constraint f foreign key (i) references parent(id) on delete cascade)", | ||
}, | ||
{ | ||
name: "two identical foreign keys, dropping one", | ||
from: "create table t1 (id int primary key, i int, key i_idex (i), constraint f1 foreign key (i) references parent(id), constraint f2 foreign key (i) references parent(id))", | ||
to: "create table t2 (id int primary key, i int, key i_idex (i), constraint f1 foreign key (i) references parent(id))", | ||
diff: "alter table t1 drop foreign key f2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming we'll always drop the second one that we parse from left to right and this won't be flaky. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, and yes this is consistent, but let me check what makes it consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK the order is left-to-right (order of definition), and not |
||
cdiff: "ALTER TABLE `t1` DROP FOREIGN KEY `f2`", | ||
}, | ||
{ | ||
name: "two identical foreign keys, dropping one, ignore vitess names", | ||
from: "create table t1 (id int primary key, i int, key i_idex (i), constraint f1 foreign key (i) references parent(id), constraint f2 foreign key (i) references parent(id))", | ||
to: "create table t2 (id int primary key, i int, key i_idex (i), constraint f1 foreign key (i) references parent(id))", | ||
diff: "alter table t1 drop foreign key f2", | ||
cdiff: "ALTER TABLE `t1` DROP FOREIGN KEY `f2`", | ||
constraint: ConstraintNamesIgnoreVitess, | ||
}, | ||
{ | ||
name: "two identical foreign keys, dropping one, ignore all names", | ||
from: "create table t1 (id int primary key, i int, key i_idex (i), constraint f1 foreign key (i) references parent(id), constraint f2 foreign key (i) references parent(id))", | ||
to: "create table t2 (id int primary key, i int, key i_idex (i), constraint f1 foreign key (i) references parent(id))", | ||
diff: "alter table t1 drop foreign key f2", | ||
cdiff: "ALTER TABLE `t1` DROP FOREIGN KEY `f2`", | ||
constraint: ConstraintNamesIgnoreAll, | ||
}, | ||
{ | ||
name: "add two identical foreign key constraints, ignore all names", | ||
from: "create table t1 (id int primary key, i int, key i_idex (i))", | ||
to: "create table t2 (id int primary key, i int, key i_idex (i), constraint f1 foreign key (i) references parent(id), constraint f2 foreign key (i) references parent(id))", | ||
diff: "alter table t1 add constraint f1 foreign key (i) references parent (id), add constraint f2 foreign key (i) references parent (id)", | ||
cdiff: "ALTER TABLE `t1` ADD CONSTRAINT `f1` FOREIGN KEY (`i`) REFERENCES `parent` (`id`), ADD CONSTRAINT `f2` FOREIGN KEY (`i`) REFERENCES `parent` (`id`)", | ||
constraint: ConstraintNamesIgnoreAll, | ||
}, | ||
{ | ||
name: "implicit foreign key indexes", | ||
from: "create table t1 (id int primary key, i int, key f(i), constraint f foreign key (i) references parent(id) on delete cascade)", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make it nil here then as well so that it cannot be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. So sorry to have merged this before noticing this comment. I'll address this elsewhere. I just happen to have #14373 as an open PR which I'll piggyride.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha. The linter doesn't like it. If I add
t2ConstraintsCountMap = nil
I get:Because nothing does use the map. The linter is sometimes overzealous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattlord how do you feel about adding a new scope block and a copy of the map, like so:
?