mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-20 19:38:55 -05:00
Added test for avoiding multiple parens issue.
Not a perfect test. See: https://github.com/dolthub/dolt/issues/5614 Validation for: https://github.com/dolthub/dolt/issues/5478
This commit is contained in:
@@ -957,8 +957,10 @@ func TestDescribeTableAsOf(t *testing.T) {
|
||||
enginetest.TestScript(t, newDoltHarness(t), DescribeTableAsOfScriptTest)
|
||||
}
|
||||
|
||||
func TestShowCreateTableAsOf(t *testing.T) {
|
||||
enginetest.TestScript(t, newDoltHarness(t), ShowCreateTableAsOfScriptTest)
|
||||
func TestShowCreateTable(t *testing.T) {
|
||||
for _, script := range ShowCreateTableScriptTests {
|
||||
enginetest.TestScript(t, newDoltHarness(t), script)
|
||||
}
|
||||
}
|
||||
|
||||
func TestViewsWithAsOf(t *testing.T) {
|
||||
|
||||
@@ -90,73 +90,142 @@ var ViewsWithAsOfScriptTest = queries.ScriptTest{
|
||||
},
|
||||
}
|
||||
|
||||
var ShowCreateTableAsOfScriptTest = queries.ScriptTest{
|
||||
Name: "Show create table as of",
|
||||
SetUpScript: []string{
|
||||
"set @Commit0 = '';",
|
||||
"set @Commit1 = '';",
|
||||
"set @Commit2 = '';",
|
||||
"set @Commit3 = '';",
|
||||
"set @Commit0 = hashof('main');",
|
||||
"create table a (pk int primary key, c1 int);",
|
||||
"call dolt_add('.');",
|
||||
"call dolt_commit_hash_out(@Commit1, '-am', 'creating table a');",
|
||||
"alter table a add column c2 varchar(20);",
|
||||
"call dolt_commit_hash_out(@Commit2, '-am', 'adding column c2');",
|
||||
"alter table a drop column c1;",
|
||||
"alter table a add constraint unique_c2 unique(c2);",
|
||||
"call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c1');",
|
||||
var ShowCreateTableScriptTests = []queries.ScriptTest{
|
||||
{
|
||||
Name: "Show create table as of",
|
||||
SetUpScript: []string{
|
||||
"set @Commit0 = '';",
|
||||
"set @Commit1 = '';",
|
||||
"set @Commit2 = '';",
|
||||
"set @Commit3 = '';",
|
||||
"set @Commit0 = hashof('main');",
|
||||
"create table a (pk int primary key, c1 int);",
|
||||
"call dolt_add('.');",
|
||||
"call dolt_commit_hash_out(@Commit1, '-am', 'creating table a');",
|
||||
"alter table a add column c2 varchar(20);",
|
||||
"call dolt_commit_hash_out(@Commit2, '-am', 'adding column c2');",
|
||||
"alter table a drop column c1;",
|
||||
"alter table a add constraint unique_c2 unique(c2);",
|
||||
"call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c1');",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "show create table a as of @Commit0;",
|
||||
ExpectedErr: sql.ErrTableNotFound,
|
||||
},
|
||||
{
|
||||
Query: "show create table a as of @Commit1;",
|
||||
Expected: []sql.Row{
|
||||
{"a", "CREATE TABLE `a` (\n" +
|
||||
" `pk` int NOT NULL,\n" +
|
||||
" `c1` int,\n" +
|
||||
" PRIMARY KEY (`pk`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "show create table a as of @Commit2;",
|
||||
Expected: []sql.Row{
|
||||
{"a", "CREATE TABLE `a` (\n" +
|
||||
" `pk` int NOT NULL,\n" +
|
||||
" `c1` int,\n" +
|
||||
" `c2` varchar(20),\n" +
|
||||
" PRIMARY KEY (`pk`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "show create table a as of @Commit3;",
|
||||
Expected: []sql.Row{
|
||||
{"a", "CREATE TABLE `a` (\n" +
|
||||
" `pk` int NOT NULL,\n" +
|
||||
" `c2` varchar(20),\n" +
|
||||
" PRIMARY KEY (`pk`),\n" +
|
||||
" UNIQUE KEY `unique_c2` (`c2`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "show create table a as of HEAD;",
|
||||
Expected: []sql.Row{
|
||||
{"a", "CREATE TABLE `a` (\n" +
|
||||
" `pk` int NOT NULL,\n" +
|
||||
" `c2` varchar(20),\n" +
|
||||
" PRIMARY KEY (`pk`),\n" +
|
||||
" UNIQUE KEY `unique_c2` (`c2`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "show create table a as of @Commit0;",
|
||||
ExpectedErr: sql.ErrTableNotFound,
|
||||
{
|
||||
// "https://github.com/dolthub/dolt/issues/5478"
|
||||
Name: "show table for default types with unique indexes",
|
||||
SetUpScript: []string{
|
||||
`create table tbl (a int primary key,
|
||||
b int not null default 42,
|
||||
c int not null default (24),
|
||||
d int not null default '-108',
|
||||
e int not null default ((((7+11)))),
|
||||
f int default (now()))`,
|
||||
`call dolt_commit('-Am', 'new table');`,
|
||||
`create index tbl_bc on tbl (b,c);`,
|
||||
`create unique index tbl_cbd on tbl (c,b,d);`,
|
||||
`create unique index tbl_c on tbl (c);`,
|
||||
`create unique index tbl_e on tbl (e);`,
|
||||
},
|
||||
{
|
||||
Query: "show create table a as of @Commit1;",
|
||||
Expected: []sql.Row{
|
||||
{"a", "CREATE TABLE `a` (\n" +
|
||||
" `pk` int NOT NULL,\n" +
|
||||
" `c1` int,\n" +
|
||||
" PRIMARY KEY (`pk`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "show create table tbl",
|
||||
Expected: []sql.Row{sql.Row{"tbl", "CREATE TABLE `tbl` (\n" +
|
||||
" `a` int NOT NULL,\n" +
|
||||
" `b` int NOT NULL DEFAULT '42',\n" + //
|
||||
" `c` int NOT NULL DEFAULT (24),\n" + // Ensure these match setup above.
|
||||
" `d` int NOT NULL DEFAULT '-108',\n" + //
|
||||
" `e` int NOT NULL DEFAULT ((7 + 11)),\n" + // Matches MySQL behavior.
|
||||
" `f` int DEFAULT (NOW()),\n" + // MySql preserves now as lower case.
|
||||
" PRIMARY KEY (`a`),\n" +
|
||||
" KEY `tbl_bc` (`b`,`c`),\n" +
|
||||
" UNIQUE KEY `tbl_c` (`c`),\n" +
|
||||
" UNIQUE KEY `tbl_cbd` (`c`,`b`,`d`),\n" +
|
||||
" UNIQUE KEY `tbl_e` (`e`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "show create table a as of @Commit2;",
|
||||
Expected: []sql.Row{
|
||||
{"a", "CREATE TABLE `a` (\n" +
|
||||
" `pk` int NOT NULL,\n" +
|
||||
" `c1` int,\n" +
|
||||
" `c2` varchar(20),\n" +
|
||||
" PRIMARY KEY (`pk`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// "https://github.com/dolthub/dolt/issues/5478"
|
||||
Name: "show table for default types with unique indexes no PK",
|
||||
SetUpScript: []string{
|
||||
`create table tbl (a int not null default (now()),
|
||||
b int not null default 42,
|
||||
c int not null default (24),
|
||||
d int not null default '-108',
|
||||
e int not null default ((((7+11)))));`,
|
||||
`call dolt_commit('-Am', 'new table');`,
|
||||
`create index tbl_bc on tbl (b,c);`,
|
||||
`create unique index tbl_cab on tbl (c,a,b);`,
|
||||
`create unique index tbl_c on tbl (c);`,
|
||||
`create unique index tbl_e on tbl (e);`,
|
||||
},
|
||||
{
|
||||
Query: "show create table a as of @Commit3;",
|
||||
Expected: []sql.Row{
|
||||
{"a", "CREATE TABLE `a` (\n" +
|
||||
" `pk` int NOT NULL,\n" +
|
||||
" `c2` varchar(20),\n" +
|
||||
" PRIMARY KEY (`pk`),\n" +
|
||||
" UNIQUE KEY `unique_c2` (`c2`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "show create table a as of HEAD;",
|
||||
Expected: []sql.Row{
|
||||
{"a", "CREATE TABLE `a` (\n" +
|
||||
" `pk` int NOT NULL,\n" +
|
||||
" `c2` varchar(20),\n" +
|
||||
" PRIMARY KEY (`pk`),\n" +
|
||||
" UNIQUE KEY `unique_c2` (`c2`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "show create table tbl",
|
||||
Expected: []sql.Row{sql.Row{"tbl", "CREATE TABLE `tbl` (\n" +
|
||||
" `a` int NOT NULL DEFAULT (NOW()),\n" + // MySql preserves now as lower case.
|
||||
" `b` int NOT NULL DEFAULT '42',\n" + //
|
||||
" `c` int NOT NULL DEFAULT (24),\n" + // Ensure these match setup above.
|
||||
" `d` int NOT NULL DEFAULT '-108',\n" + //
|
||||
" `e` int NOT NULL DEFAULT ((7 + 11)),\n" + // Matches MySQL behavior.
|
||||
" KEY `tbl_bc` (`b`,`c`),\n" +
|
||||
" UNIQUE KEY `tbl_c` (`c`),\n" +
|
||||
" UNIQUE KEY `tbl_cab` (`c`,`a`,`b`),\n" +
|
||||
" UNIQUE KEY `tbl_e` (`e`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user