Skip to content

Commit fbb5bdb

Browse files
committed
Add support for ALTER TABLE ... DROP CONSTRAINT ...
1 parent 60a6b48 commit fbb5bdb

File tree

3 files changed

+2496
-2509
lines changed

3 files changed

+2496
-2509
lines changed

parse_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,7 @@ func TestCreateTable(t *testing.T) {
21352135
"alter table tbl_a add index idx_ab (col_a, col_b), algorithm inplace, lock none",
21362136
"alter table tbl_a add constraint uq_ab unique key idx_ab (col_a, col_b), lock=shared",
21372137
"alter table tbl_a drop index idx_ab, lock=shared",
2138+
"alter table tbl_a drop constraint chk_a, lock=shared",
21382139
"alter table tbl_a rename index idx_old to idx_new, algorithm=instant",
21392140
"alter table tbl_a rename column col_old to col_new, algorithm=instant, lock=none",
21402141
}
@@ -2150,6 +2151,7 @@ func TestCreateTable(t *testing.T) {
21502151
"alter table tbl_a add index idx_ab (col_a, col_b)",
21512152
"alter table tbl_a add (col_a int)",
21522153
"alter table tbl_a drop foreign key fk_ab",
2154+
"alter table tbl_a drop constraint chk_a",
21532155
}
21542156
for _, sql := range validAlterTableRegressionSQL {
21552157
tree, err := ParseStrictDDL(sql)
@@ -2163,6 +2165,7 @@ func TestCreateTable(t *testing.T) {
21632165
"alter table tbl_c add index idx_c1 (c1), drop index idx_c1",
21642166
"alter table tbl_c2 drop column c2",
21652167
"alter table tbl_d add (c4 int), drop foreign key fk_c4",
2168+
"alter table tbl_drop_chk drop constraint chk_a, add column col_a int null",
21662169
"alter table tbl_h add index idx_c6 (c6), lock shared, algorithm inplace",
21672170
"alter table tbl_i drop key idx_c7, modify c7 varchar(128) not null, add column c8 binary(16) not null, add unique (c8)",
21682171
"alter table tbl_m drop key idx_c9, modify column c9 varchar(64) not null, add unique (c9)",
@@ -2299,6 +2302,8 @@ func TestCreateTable(t *testing.T) {
22992302
"alter table tbl_l4 add column col_a int, rename column col_b to",
23002303
// RENAME COLUMN requires the TO keyword.
23012304
"alter table tbl_l5 add column col_a int, rename column col_b col_c",
2305+
// DROP CONSTRAINT requires a constraint identifier before the next item.
2306+
"alter table tbl_l6 drop constraint, add column col_a int",
23022307
}
23032308
for _, sql := range invalidAlterTableMultiSpecSQL {
23042309
tree, err := ParseStrictDDL(sql)
@@ -2319,6 +2324,7 @@ func TestCreateTable(t *testing.T) {
23192324
"alter table tbl_incomplete modify column col_a",
23202325
"alter table tbl_incomplete drop foreign key",
23212326
"alter table tbl_incomplete drop constraint",
2327+
"alter table tbl_incomplete drop constraint primary key",
23222328
"alter table tbl_incomplete rename key",
23232329
"alter table tbl_incomplete rename column",
23242330
"alter table tbl_incomplete rename column col_a",

0 commit comments

Comments
 (0)