Skip to content

Commit 15fcf80

Browse files
author
James Cor
committed
refactor and clean up
1 parent c430a1c commit 15fcf80

File tree

2 files changed

+75
-73
lines changed

2 files changed

+75
-73
lines changed

enginetest/queries/alter_table_queries.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,54 @@ var AlterTableAddAutoIncrementScripts = []ScriptTest{
14561456
},
14571457
},
14581458
},
1459+
{
1460+
Name: "ALTER AUTO INCREMENT TABLE ADD column",
1461+
SetUpScript: []string{
1462+
"CREATE TABLE test (pk int primary key, uk int UNIQUE KEY auto_increment);",
1463+
},
1464+
Assertions: []ScriptTestAssertion{
1465+
{
1466+
Query: "alter table test add column j int;",
1467+
Expected: []sql.Row{{types.NewOkResult(0)}},
1468+
},
1469+
},
1470+
},
1471+
{
1472+
Name: "ALTER TABLE MODIFY column with multiple UNIQUE KEYS",
1473+
Dialect: "mysql",
1474+
SetUpScript: []string{
1475+
"CREATE table test (pk int primary key, uk1 int, uk2 int, unique(uk1, uk2))",
1476+
"ALTER TABLE `test` MODIFY column uk1 int auto_increment",
1477+
},
1478+
Assertions: []ScriptTestAssertion{
1479+
{
1480+
Query: "describe test",
1481+
Expected: []sql.Row{
1482+
{"pk", "int", "NO", "PRI", nil, ""},
1483+
{"uk1", "int", "NO", "MUL", nil, "auto_increment"},
1484+
{"uk2", "int", "YES", "", nil, ""},
1485+
},
1486+
},
1487+
},
1488+
},
1489+
{
1490+
Name: "ALTER TABLE MODIFY column with multiple KEYS",
1491+
Dialect: "mysql",
1492+
SetUpScript: []string{
1493+
"CREATE table test (pk int primary key, mk1 int, mk2 int, index(mk1, mk2))",
1494+
"ALTER TABLE `test` MODIFY column mk1 int auto_increment",
1495+
},
1496+
Assertions: []ScriptTestAssertion{
1497+
{
1498+
Query: "describe test",
1499+
Expected: []sql.Row{
1500+
{"pk", "int", "NO", "PRI", nil, ""},
1501+
{"mk1", "int", "NO", "MUL", nil, "auto_increment"},
1502+
{"mk2", "int", "YES", "", nil, ""},
1503+
},
1504+
},
1505+
},
1506+
},
14591507
}
14601508

14611509
var AddDropPrimaryKeyScripts = []ScriptTest{

enginetest/queries/script_queries.go

Lines changed: 27 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ CREATE TABLE sourceTable_test (
245245
},
246246
},
247247
{
248-
Name: "GMS issue 2369",
248+
// https://github.com/dolthub/go-mysql-server/issues/2369
249+
Name: "auto_increment with self-referencing foreign key",
249250
SetUpScript: []string{
250251
`CREATE TABLE table1 (
251252
id int NOT NULL AUTO_INCREMENT,
@@ -278,6 +279,31 @@ CREATE TABLE sourceTable_test (
278279
},
279280
},
280281
},
282+
{
283+
// https://github.com/dolthub/go-mysql-server/issues/2349
284+
Name: "auto_increment with foreign key",
285+
SetUpScript: []string{
286+
"CREATE TABLE table1 (id int NOT NULL AUTO_INCREMENT primary key, name text)",
287+
`
288+
CREATE TABLE table2 (
289+
id int NOT NULL AUTO_INCREMENT,
290+
name text,
291+
fk int,
292+
PRIMARY KEY (id),
293+
CONSTRAINT myConstraint FOREIGN KEY (fk) REFERENCES table1 (id)
294+
)`,
295+
},
296+
Assertions: []ScriptTestAssertion{
297+
{
298+
Query: "INSERT INTO table1 (name) VALUES ('tbl1 row 1');",
299+
Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 1}}},
300+
},
301+
{
302+
Query: "INSERT INTO table1 (name) VALUES ('tbl1 row 2');",
303+
Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 2}}},
304+
},
305+
},
306+
},
281307
{
282308
Name: "index match only exact string, no prefix",
283309
SetUpScript: []string{
@@ -517,30 +543,6 @@ SET entity_test.value = joined.value;`,
517543
},
518544
},
519545
},
520-
{
521-
Name: "GMS issue 2349",
522-
SetUpScript: []string{
523-
"CREATE TABLE table1 (id int NOT NULL AUTO_INCREMENT primary key, name text)",
524-
`
525-
CREATE TABLE table2 (
526-
id int NOT NULL AUTO_INCREMENT,
527-
name text,
528-
fk int,
529-
PRIMARY KEY (id),
530-
CONSTRAINT myConstraint FOREIGN KEY (fk) REFERENCES table1 (id)
531-
)`,
532-
},
533-
Assertions: []ScriptTestAssertion{
534-
{
535-
Query: "INSERT INTO table1 (name) VALUES ('tbl1 row 1');",
536-
Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 1}}},
537-
},
538-
{
539-
Query: "INSERT INTO table1 (name) VALUES ('tbl1 row 2');",
540-
Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 2}}},
541-
},
542-
},
543-
},
544546
{
545547
Name: "missing indexes",
546548
SetUpScript: []string{
@@ -3675,18 +3677,6 @@ CREATE TABLE tab3 (
36753677
},
36763678
},
36773679
},
3678-
{
3679-
Name: "ALTER AUTO INCREMENT TABLE ADD column",
3680-
SetUpScript: []string{
3681-
"CREATE TABLE test (pk int primary key, uk int UNIQUE KEY auto_increment);",
3682-
},
3683-
Assertions: []ScriptTestAssertion{
3684-
{
3685-
Query: "alter table test add column j int;",
3686-
Expected: []sql.Row{{types.NewOkResult(0)}},
3687-
},
3688-
},
3689-
},
36903680
{
36913681
Name: "alter json column default; from scorewarrior: https://github.com/dolthub/dolt/issues/4543",
36923682
SetUpScript: []string{
@@ -3897,42 +3887,6 @@ CREATE TABLE tab3 (
38973887
},
38983888
},
38993889
},
3900-
{
3901-
Name: "ALTER TABLE MODIFY column with multiple UNIQUE KEYS",
3902-
Dialect: "mysql",
3903-
SetUpScript: []string{
3904-
"CREATE table test (pk int primary key, uk1 int, uk2 int, unique(uk1, uk2))",
3905-
"ALTER TABLE `test` MODIFY column uk1 int auto_increment",
3906-
},
3907-
Assertions: []ScriptTestAssertion{
3908-
{
3909-
Query: "describe test",
3910-
Expected: []sql.Row{
3911-
{"pk", "int", "NO", "PRI", nil, ""},
3912-
{"uk1", "int", "NO", "MUL", nil, "auto_increment"},
3913-
{"uk2", "int", "YES", "", nil, ""},
3914-
},
3915-
},
3916-
},
3917-
},
3918-
{
3919-
Name: "ALTER TABLE MODIFY column with multiple KEYS",
3920-
Dialect: "mysql",
3921-
SetUpScript: []string{
3922-
"CREATE table test (pk int primary key, mk1 int, mk2 int, index(mk1, mk2))",
3923-
"ALTER TABLE `test` MODIFY column mk1 int auto_increment",
3924-
},
3925-
Assertions: []ScriptTestAssertion{
3926-
{
3927-
Query: "describe test",
3928-
Expected: []sql.Row{
3929-
{"pk", "int", "NO", "PRI", nil, ""},
3930-
{"mk1", "int", "NO", "MUL", nil, "auto_increment"},
3931-
{"mk2", "int", "YES", "", nil, ""},
3932-
},
3933-
},
3934-
},
3935-
},
39363890
{
39373891
// https://github.com/dolthub/dolt/issues/3065
39383892
Name: "join index lookups do not handle filters",

0 commit comments

Comments
 (0)