github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/sqle/enginetest/dolt_queries.go (about) 1 // Copyright 2021 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package enginetest 16 17 import ( 18 "fmt" 19 "strings" 20 21 "github.com/dolthub/go-mysql-server/enginetest/queries" 22 "github.com/dolthub/go-mysql-server/sql" 23 "github.com/dolthub/go-mysql-server/sql/plan" 24 "github.com/dolthub/go-mysql-server/sql/types" 25 "github.com/dolthub/vitess/go/sqltypes" 26 "github.com/dolthub/vitess/go/vt/proto/query" 27 28 "github.com/dolthub/dolt/go/libraries/doltcore/sqle" 29 ) 30 31 var ViewsWithAsOfScriptTest = queries.ScriptTest{ 32 SkipPrepared: true, 33 Name: "Querying a view with a union using an as of expression", 34 SetUpScript: []string{ 35 "CALL dolt_commit('--allow-empty', '-m', 'cm0');", 36 37 "CREATE TABLE t1 (pk int PRIMARY KEY AUTO_INCREMENT, c0 int);", 38 "CALL dolt_add('.')", 39 "CALL dolt_commit('-am', 'cm1');", 40 "INSERT INTO t1 (c0) VALUES (1), (2);", 41 "CALL dolt_commit('-am', 'cm2');", 42 43 "CREATE TABLE t2 (pk int PRIMARY KEY AUTO_INCREMENT, vc varchar(100));", 44 "CALL dolt_add('.')", 45 "CALL dolt_commit('-am', 'cm3');", 46 "INSERT INTO t2 (vc) VALUES ('one'), ('two');", 47 "CALL dolt_commit('-am', 'cm4');", 48 49 "CREATE VIEW v1 as select * from t1 union select * from t2", 50 "call dolt_add('.');", 51 "CALL dolt_commit('-am', 'cm5');", 52 }, 53 Assertions: []queries.ScriptTestAssertion{ 54 { 55 Query: "select * from v1", 56 Expected: []sql.Row{{1, "1"}, {2, "2"}, {1, "one"}, {2, "two"}}, 57 }, 58 { 59 Query: "select * from v1 as of 'HEAD'", 60 Expected: []sql.Row{{1, "1"}, {2, "2"}, {1, "one"}, {2, "two"}}, 61 }, 62 { 63 Query: "select * from v1 as of 'HEAD~1'", 64 Expected: []sql.Row{{1, "1"}, {2, "2"}, {1, "one"}, {2, "two"}}, 65 }, 66 { 67 Query: "select * from v1 as of 'HEAD~2'", 68 Expected: []sql.Row{{1, "1"}, {2, "2"}}, 69 }, 70 { 71 // At this point table t1 doesn't exist yet, so the view should return an error 72 Query: "select * from v1 as of 'HEAD~3'", 73 ExpectedErrStr: "View 'mydb.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them", 74 }, 75 { 76 Query: "select * from v1 as of 'HEAD~4'", 77 ExpectedErrStr: "View 'mydb.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them", 78 }, 79 { 80 Query: "select * from v1 as of 'HEAD~5'", 81 ExpectedErrStr: "View 'mydb.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them", 82 }, 83 { 84 Query: "select * from v1 as of HEAD", 85 Expected: []sql.Row{{1, "1"}, {2, "2"}, {1, "one"}, {2, "two"}}, 86 }, 87 { 88 Query: "select * from v1 as of HEAD.ASDF", 89 ExpectedErrStr: "branch not found: HEAD.ASDF", 90 }, 91 }, 92 } 93 94 var ShowCreateTableScriptTests = []queries.ScriptTest{ 95 { 96 Name: "Show create table as of", 97 SetUpScript: []string{ 98 "set @Commit0 = '';", 99 "set @Commit1 = '';", 100 "set @Commit2 = '';", 101 "set @Commit3 = '';", 102 "set @Commit0 = hashof('main');", 103 "create table a (pk int primary key, c1 int);", 104 "call dolt_add('.');", 105 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table a');", 106 "alter table a add column c2 varchar(20);", 107 "call dolt_commit_hash_out(@Commit2, '-am', 'adding column c2');", 108 "alter table a drop column c1;", 109 "alter table a add constraint unique_c2 unique(c2);", 110 "call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c1');", 111 }, 112 Assertions: []queries.ScriptTestAssertion{ 113 { 114 Query: "show create table a as of @Commit0;", 115 ExpectedErr: sql.ErrTableNotFound, 116 }, 117 { 118 Query: "show create table a as of @Commit1;", 119 Expected: []sql.Row{ 120 {"a", "CREATE TABLE `a` (\n" + 121 " `pk` int NOT NULL,\n" + 122 " `c1` int,\n" + 123 " PRIMARY KEY (`pk`)\n" + 124 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", 125 }, 126 }, 127 }, 128 { 129 Query: "show create table a as of @Commit2;", 130 Expected: []sql.Row{ 131 {"a", "CREATE TABLE `a` (\n" + 132 " `pk` int NOT NULL,\n" + 133 " `c1` int,\n" + 134 " `c2` varchar(20),\n" + 135 " PRIMARY KEY (`pk`)\n" + 136 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", 137 }, 138 }, 139 }, 140 { 141 Query: "show create table a as of @Commit3;", 142 Expected: []sql.Row{ 143 {"a", "CREATE TABLE `a` (\n" + 144 " `pk` int NOT NULL,\n" + 145 " `c2` varchar(20),\n" + 146 " PRIMARY KEY (`pk`),\n" + 147 " UNIQUE KEY `unique_c2` (`c2`)\n" + 148 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", 149 }, 150 }, 151 }, 152 { 153 Query: "show create table a as of HEAD;", 154 Expected: []sql.Row{ 155 {"a", "CREATE TABLE `a` (\n" + 156 " `pk` int NOT NULL,\n" + 157 " `c2` varchar(20),\n" + 158 " PRIMARY KEY (`pk`),\n" + 159 " UNIQUE KEY `unique_c2` (`c2`)\n" + 160 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", 161 }, 162 }, 163 }, 164 }, 165 }, 166 { 167 // "https://github.com/dolthub/dolt/issues/5478" 168 Name: "show table for default types with unique indexes", 169 SetUpScript: []string{ 170 `create table tbl (a int primary key, 171 b int not null default 42, 172 c int not null default (24), 173 d int not null default '-108', 174 e int not null default ((((7+11)))), 175 f int default (now()))`, 176 `call dolt_commit('-Am', 'new table');`, 177 `create index tbl_bc on tbl (b,c);`, 178 `create unique index tbl_cbd on tbl (c,b,d);`, 179 `create unique index tbl_c on tbl (c);`, 180 `create unique index tbl_e on tbl (e);`, 181 }, 182 Assertions: []queries.ScriptTestAssertion{ 183 { 184 Query: "show create table tbl", 185 Expected: []sql.Row{{"tbl", "CREATE TABLE `tbl` (\n" + 186 " `a` int NOT NULL,\n" + 187 " `b` int NOT NULL DEFAULT '42',\n" + // 188 " `c` int NOT NULL DEFAULT (24),\n" + // Ensure these match setup above. 189 " `d` int NOT NULL DEFAULT '-108',\n" + // 190 " `e` int NOT NULL DEFAULT ((7 + 11)),\n" + // Matches MySQL behavior. 191 " `f` int DEFAULT CURRENT_TIMESTAMP,\n" + // MySql preserves now as lower case. 192 " PRIMARY KEY (`a`),\n" + 193 " KEY `tbl_bc` (`b`,`c`),\n" + 194 " UNIQUE KEY `tbl_c` (`c`),\n" + 195 " UNIQUE KEY `tbl_cbd` (`c`,`b`,`d`),\n" + 196 " UNIQUE KEY `tbl_e` (`e`)\n" + 197 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 198 }, 199 }, 200 }, 201 { 202 // "https://github.com/dolthub/dolt/issues/5478" 203 Name: "show table for default types with unique indexes no PK", 204 SetUpScript: []string{ 205 `create table tbl (a int not null default (now()), 206 b int not null default 42, 207 c int not null default (24), 208 d int not null default '-108', 209 e int not null default ((((7+11)))));`, 210 `call dolt_commit('-Am', 'new table');`, 211 `create index tbl_bc on tbl (b,c);`, 212 `create unique index tbl_cab on tbl (c,a,b);`, 213 `create unique index tbl_c on tbl (c);`, 214 `create unique index tbl_e on tbl (e);`, 215 }, 216 Assertions: []queries.ScriptTestAssertion{ 217 { 218 Query: "show create table tbl", 219 Expected: []sql.Row{{"tbl", "CREATE TABLE `tbl` (\n" + 220 " `a` int NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" + // MySql preserves now as lower case. 221 " `b` int NOT NULL DEFAULT '42',\n" + // 222 " `c` int NOT NULL DEFAULT (24),\n" + // Ensure these match setup above. 223 " `d` int NOT NULL DEFAULT '-108',\n" + // 224 " `e` int NOT NULL DEFAULT ((7 + 11)),\n" + // Matches MySQL behavior. 225 " KEY `tbl_bc` (`b`,`c`),\n" + 226 " UNIQUE KEY `tbl_c` (`c`),\n" + 227 " UNIQUE KEY `tbl_cab` (`c`,`a`,`b`),\n" + 228 " UNIQUE KEY `tbl_e` (`e`)\n" + 229 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 230 }, 231 }, 232 }, 233 { 234 Name: "Show create table as of with FKs", 235 SetUpScript: []string{ 236 "set @Commit0 = '';", 237 "set @Commit1 = '';", 238 "set @Commit2 = '';", 239 "set @Commit3 = '';", 240 "set @Commit0 = hashof('main');", 241 "create table parent(id int primary key, pv1 int, pv2 varchar(20), index v1 (pv1), index v2 (pv2));", 242 "create table child (pk int primary key, c1 int, c3 int);", 243 "alter table child add constraint fk1 foreign key (c1) references parent(pv1);", 244 "call dolt_add('.');", 245 "call dolt_commit_hash_out(@Commit1, '-am', 'creating tables parent and child');", 246 "alter table child add column c2 varchar(20);", 247 "alter table child drop foreign key fk1;", 248 "alter table child add constraint fk2 foreign key (c2) references parent(pv2);", 249 "call dolt_commit_hash_out(@Commit2, '-am', 'adding column c2 and constraint');", 250 "alter table child drop column c1;", 251 "alter table child add constraint unique_c2 unique(c2);", 252 "call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c1');", 253 }, 254 Assertions: []queries.ScriptTestAssertion{ 255 { 256 Query: "show create table child as of @Commit0;", 257 ExpectedErr: sql.ErrTableNotFound, 258 }, 259 { 260 Query: "show create table child as of @Commit1;", 261 Expected: []sql.Row{ 262 {"child", "CREATE TABLE `child` (\n" + 263 " `pk` int NOT NULL,\n" + 264 " `c1` int,\n" + 265 " `c3` int,\n" + 266 " PRIMARY KEY (`pk`),\n" + 267 " KEY `c1` (`c1`),\n" + 268 " CONSTRAINT `fk1` FOREIGN KEY (`c1`) REFERENCES `parent` (`pv1`)\n" + 269 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", 270 }, 271 }, 272 }, 273 { 274 Query: "show create table child as of @Commit2;", 275 Expected: []sql.Row{ 276 {"child", "CREATE TABLE `child` (\n" + 277 " `pk` int NOT NULL,\n" + 278 " `c1` int,\n" + 279 " `c3` int,\n" + 280 " `c2` varchar(20),\n" + 281 " PRIMARY KEY (`pk`),\n" + 282 " KEY `c1` (`c1`),\n" + 283 " KEY `c2` (`c2`),\n" + 284 " CONSTRAINT `fk2` FOREIGN KEY (`c2`) REFERENCES `parent` (`pv2`)\n" + 285 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", 286 }, 287 }, 288 }, 289 { 290 Query: "show create table child as of @Commit3;", 291 Expected: []sql.Row{ 292 {"child", "CREATE TABLE `child` (\n" + 293 " `pk` int NOT NULL,\n" + 294 " `c3` int,\n" + 295 " `c2` varchar(20),\n" + 296 " PRIMARY KEY (`pk`),\n" + 297 " UNIQUE KEY `unique_c2` (`c2`),\n" + 298 " CONSTRAINT `fk2` FOREIGN KEY (`c2`) REFERENCES `parent` (`pv2`)\n" + 299 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", 300 }, 301 }, 302 }, 303 { 304 Query: "show create table child as of HEAD;", 305 Expected: []sql.Row{ 306 {"child", "CREATE TABLE `child` (\n" + 307 " `pk` int NOT NULL,\n" + 308 " `c3` int,\n" + 309 " `c2` varchar(20),\n" + 310 " PRIMARY KEY (`pk`),\n" + 311 " UNIQUE KEY `unique_c2` (`c2`),\n" + 312 " CONSTRAINT `fk2` FOREIGN KEY (`c2`) REFERENCES `parent` (`pv2`)\n" + 313 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", 314 }, 315 }, 316 }, 317 }, 318 }, 319 } 320 321 var DescribeTableAsOfScriptTest = queries.ScriptTest{ 322 Name: "Describe table as of", 323 SetUpScript: []string{ 324 "set @Commit0 = '';", 325 "set @Commit1 = '';", 326 "set @Commit2 = '';", 327 "set @Commit3 = '';", 328 "call dolt_commit_hash_out(@Commit0, '--allow-empty', '-m', 'before creating table a');", 329 "create table a (pk int primary key, c1 int);", 330 "call dolt_add('.');", 331 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table a');", 332 "alter table a add column c2 varchar(20);", 333 "call dolt_commit_hash_out(@Commit2, '-am', 'adding column c2');", 334 "alter table a drop column c1;", 335 "call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c1');", 336 }, 337 Assertions: []queries.ScriptTestAssertion{ 338 { 339 Query: "describe a as of @Commit0;", 340 ExpectedErr: sql.ErrTableNotFound, 341 }, 342 { 343 Query: "describe a as of @Commit1;", 344 Expected: []sql.Row{ 345 {"pk", "int", "NO", "PRI", nil, ""}, 346 {"c1", "int", "YES", "", nil, ""}, 347 }, 348 }, 349 { 350 Query: "describe a as of @Commit2;", 351 Expected: []sql.Row{ 352 {"pk", "int", "NO", "PRI", nil, ""}, 353 {"c1", "int", "YES", "", nil, ""}, 354 {"c2", "varchar(20)", "YES", "", nil, ""}, 355 }, 356 }, 357 { 358 Query: "describe a as of @Commit3;", 359 Expected: []sql.Row{ 360 {"pk", "int", "NO", "PRI", nil, ""}, 361 {"c2", "varchar(20)", "YES", "", nil, ""}, 362 }, 363 }, 364 { 365 Query: "describe a as of HEAD;", 366 Expected: []sql.Row{ 367 {"pk", "int", "NO", "PRI", nil, ""}, 368 {"c2", "varchar(20)", "YES", "", nil, ""}, 369 }, 370 }, 371 }, 372 } 373 374 var DoltRevisionDbScripts = []queries.ScriptTest{ 375 { 376 Name: "database revision specs: Ancestor references", 377 SetUpScript: []string{ 378 "create table t01 (pk int primary key, c1 int)", 379 "call dolt_add('t01');", 380 "call dolt_commit('-am', 'creating table t01 on main');", 381 "call dolt_branch('branch1');", 382 "insert into t01 values (1, 1), (2, 2);", 383 "call dolt_commit('-am', 'adding rows to table t01 on main');", 384 "insert into t01 values (3, 3);", 385 "call dolt_commit('-am', 'adding another row to table t01 on main');", 386 "call dolt_tag('tag1');", 387 "call dolt_checkout('branch1');", 388 "insert into t01 values (100, 100), (200, 200);", 389 "call dolt_commit('-am', 'inserting rows in t01 on branch1');", 390 "insert into t01 values (1000, 1000);", 391 "call dolt_commit('-am', 'inserting another row in t01 on branch1');", 392 }, 393 Assertions: []queries.ScriptTestAssertion{ 394 { 395 Query: "show databases;", 396 Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}}, 397 }, 398 { 399 Query: "use `mydb/tag1~`;", 400 Expected: []sql.Row{}, 401 }, 402 { 403 // The database name is always the requested name 404 Query: "select database()", 405 Expected: []sql.Row{{"mydb/tag1~"}}, 406 }, 407 { 408 Query: "show databases;", 409 Expected: []sql.Row{{"mydb"}, {"mydb/tag1~"}, {"information_schema"}, {"mysql"}}, 410 }, 411 { 412 // The branch is nil in the case of a non-branch revision DB 413 Query: "select active_branch()", 414 Expected: []sql.Row{{nil}}, 415 }, 416 { 417 Query: "select * from t01;", 418 Expected: []sql.Row{{1, 1}, {2, 2}}, 419 }, 420 { 421 Query: "select * from `mydb/tag1^`.t01;", 422 Expected: []sql.Row{{1, 1}, {2, 2}}, 423 }, 424 { 425 // Only merge commits are valid for ^2 ancestor spec 426 Query: "select * from `mydb/tag1^2`.t01;", 427 ExpectedErrStr: "invalid ancestor spec", 428 }, 429 { 430 Query: "select * from `mydb/tag1~1`.t01;", 431 Expected: []sql.Row{{1, 1}, {2, 2}}, 432 }, 433 { 434 Query: "select * from `mydb/tag1~2`.t01;", 435 Expected: []sql.Row{}, 436 }, 437 { 438 Query: "select * from `mydb/tag1~3`.t01;", 439 ExpectedErr: sql.ErrTableNotFound, 440 }, 441 { 442 Query: "select * from `mydb/tag1~20`.t01;", 443 ExpectedErrStr: "invalid ancestor spec", 444 }, 445 { 446 Query: "select * from `mydb/branch1~`.t01;", 447 Expected: []sql.Row{{100, 100}, {200, 200}}, 448 }, 449 { 450 Query: "select * from `mydb/branch1^`.t01;", 451 Expected: []sql.Row{{100, 100}, {200, 200}}, 452 }, 453 { 454 Query: "select * from `mydb/branch1~2`.t01;", 455 Expected: []sql.Row{}, 456 }, 457 { 458 Query: "select * from `mydb/branch1~3`.t01;", 459 ExpectedErr: sql.ErrTableNotFound, 460 }, 461 }, 462 }, 463 { 464 Name: "database revision specs: tag-qualified revision spec", 465 SetUpScript: []string{ 466 "create table t01 (pk int primary key, c1 int)", 467 "call dolt_add('.')", 468 "call dolt_commit('-am', 'creating table t01 on main');", 469 "insert into t01 values (1, 1), (2, 2);", 470 "call dolt_commit('-am', 'adding rows to table t01 on main');", 471 "call dolt_tag('tag1');", 472 "insert into t01 values (3, 3);", 473 "call dolt_commit('-am', 'adding another row to table t01 on main');", 474 }, 475 Assertions: []queries.ScriptTestAssertion{ 476 { 477 Query: "show databases;", 478 Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}}, 479 }, 480 { 481 Query: "use mydb/tag1;", 482 Expected: []sql.Row{}, 483 }, 484 { 485 // The database name is always the requested name 486 Query: "select database()", 487 Expected: []sql.Row{{"mydb/tag1"}}, 488 }, 489 { 490 // The branch is nil in the case of a non-branch revision DB 491 Query: "select active_branch()", 492 Expected: []sql.Row{{nil}}, 493 }, 494 { 495 Query: "show databases;", 496 Expected: []sql.Row{{"mydb"}, {"mydb/tag1"}, {"information_schema"}, {"mysql"}}, 497 }, 498 { 499 Query: "select * from t01;", 500 Expected: []sql.Row{{1, 1}, {2, 2}}, 501 }, 502 { 503 Query: "call dolt_reset();", 504 ExpectedErrStr: "unable to reset HEAD in read-only databases", 505 }, 506 { 507 Query: "call dolt_checkout('main');", 508 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 509 }, 510 { 511 Query: "select database();", 512 Expected: []sql.Row{{"mydb"}}, 513 }, 514 { 515 Query: "select active_branch();", 516 Expected: []sql.Row{{"main"}}, 517 }, 518 { 519 Query: "use mydb;", 520 Expected: []sql.Row{}, 521 }, 522 { 523 Query: "select database();", 524 Expected: []sql.Row{{"mydb"}}, 525 }, 526 { 527 Query: "show databases;", 528 Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}}, 529 }, 530 }, 531 }, 532 { 533 Name: "database revision specs: branch-qualified revision spec", 534 SetUpScript: []string{ 535 "create table t01 (pk int primary key, c1 int)", 536 "call dolt_add('.')", 537 "call dolt_commit('-am', 'creating table t01 on main');", 538 "insert into t01 values (1, 1), (2, 2);", 539 "call dolt_commit('-am', 'adding rows to table t01 on main');", 540 "call dolt_branch('branch1');", 541 "insert into t01 values (3, 3);", 542 "call dolt_commit('-am', 'adding another row to table t01 on main');", 543 }, 544 Assertions: []queries.ScriptTestAssertion{ 545 { 546 Query: "use mydb/branch1;", 547 Expected: []sql.Row{}, 548 }, 549 { 550 Query: "show databases;", 551 Expected: []sql.Row{{"mydb"}, {"mydb/branch1"}, {"information_schema"}, {"mysql"}}, 552 }, 553 { 554 // The database name is always the requested name 555 Query: "select database()", 556 Expected: []sql.Row{{"mydb/branch1"}}, 557 }, 558 { 559 Query: "select active_branch()", 560 Expected: []sql.Row{{"branch1"}}, 561 }, 562 { 563 Query: "select * from t01", 564 Expected: []sql.Row{{1, 1}, {2, 2}}, 565 }, 566 { 567 Query: "call dolt_checkout('main');", 568 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 569 }, 570 { 571 // TODO: the behavior here is a bit odd: when we call dolt_checkout, we change the current database to the 572 // base database name. But we should also consider the connection string: if you connect to a revision 573 // database, that database should always be visible. 574 Query: "show databases;", 575 Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}}, 576 }, 577 { 578 Query: "select database();", 579 Expected: []sql.Row{{"mydb"}}, 580 }, 581 { 582 Query: "use mydb/branch1;", 583 Expected: []sql.Row{}, 584 }, 585 { 586 Query: "call dolt_reset();", 587 Expected: []sql.Row{{0}}, 588 }, 589 { 590 Query: "select database();", 591 Expected: []sql.Row{{"mydb/branch1"}}, 592 }, 593 { 594 Query: "show databases;", 595 Expected: []sql.Row{{"mydb"}, {"mydb/branch1"}, {"information_schema"}, {"mysql"}}, 596 }, 597 { 598 // Create a table in the working set to verify the main db 599 Query: "create table working_set_table(pk int primary key);", 600 Expected: []sql.Row{{types.NewOkResult(0)}}, 601 }, 602 { 603 Query: "select table_name from dolt_diff where commit_hash='WORKING';", 604 Expected: []sql.Row{{"working_set_table"}}, 605 }, 606 { 607 Query: "use mydb;", 608 Expected: []sql.Row{}, 609 }, 610 { 611 Query: "select table_name from dolt_diff where commit_hash='WORKING';", 612 Expected: []sql.Row{}, 613 }, 614 { 615 Query: "call dolt_checkout('branch1');", 616 Expected: []sql.Row{{0, "Switched to branch 'branch1'"}}, 617 }, 618 { 619 Query: "select table_name from dolt_diff where commit_hash='WORKING';", 620 Expected: []sql.Row{{"working_set_table"}}, 621 }, 622 }, 623 }, 624 { 625 Name: "database revision specs: dolt_checkout uses revision database name for DbData access", 626 SetUpScript: []string{ 627 "create database newtest;", 628 "use newtest;", 629 }, 630 Assertions: []queries.ScriptTestAssertion{ 631 { 632 Query: "select active_branch();", 633 Expected: []sql.Row{{"main"}}, 634 }, 635 { 636 Query: "call dolt_checkout('-b', 'branch-to-delete');", 637 Expected: []sql.Row{{0, "Switched to branch 'branch-to-delete'"}}, 638 }, 639 { 640 Query: "select active_branch();", 641 Expected: []sql.Row{{"branch-to-delete"}}, 642 }, 643 { 644 Query: "use `newtest/main`;", 645 Expected: []sql.Row{}, 646 }, 647 { 648 Query: "select active_branch();", 649 Expected: []sql.Row{{"main"}}, 650 }, 651 { 652 Query: "call dolt_branch('-D', 'branch-to-delete');", 653 Expected: []sql.Row{{0}}, 654 }, 655 { 656 Query: "select active_branch();", 657 Expected: []sql.Row{{"main"}}, 658 }, 659 { 660 Query: "call dolt_checkout('-b', 'another-branch');", 661 Expected: []sql.Row{{0, "Switched to branch 'another-branch'"}}, 662 }, 663 { 664 Query: "select active_branch();", 665 Expected: []sql.Row{{"another-branch"}}, 666 }, 667 }, 668 }, 669 { 670 Name: "database revision specs: can checkout a table", 671 SetUpScript: []string{ 672 "call dolt_checkout('main')", 673 "create table t01 (pk int primary key, c1 int)", 674 "call dolt_add('t01');", 675 "call dolt_commit('-am', 'creating table t01 on branch1');", 676 "insert into t01 values (1, 1), (2, 2);", 677 "call dolt_branch('new-branch')", 678 }, 679 Assertions: []queries.ScriptTestAssertion{ 680 { 681 Query: "show databases;", 682 Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}}, 683 }, 684 { 685 Query: "use `mydb/main`;", 686 Expected: []sql.Row{}, 687 }, 688 { 689 Query: "select * from dolt_status", 690 Expected: []sql.Row{{"t01", false, "modified"}}, 691 }, 692 { 693 Query: "call dolt_checkout('t01')", 694 Expected: []sql.Row{{0, ""}}, 695 }, 696 { 697 Query: "select * from dolt_status", 698 // Expected: []sql.Row{}, 699 SkipResultsCheck: true, // TODO: https://github.com/dolthub/dolt/issues/5816 700 }, 701 }, 702 }, 703 } 704 705 // DoltScripts are script tests specific to Dolt (not the engine in general), e.g. by involving Dolt functions. Break 706 // this slice into others with good names as it grows. 707 var DoltScripts = []queries.ScriptTest{ 708 { 709 Name: "dolt_hashof_table tests", 710 SetUpScript: []string{ 711 "CREATE TABLE t1 (pk int primary key);", 712 }, 713 Assertions: []queries.ScriptTestAssertion{ 714 { 715 Query: "SHOW TABLES;", 716 Expected: []sql.Row{ 717 {"t1"}, 718 }, 719 }, 720 { 721 Query: "SELECT dolt_hashof_table('t1');", 722 Expected: []sql.Row{{"0lvgnnqah2lj1p6ilvfg0ssaec1v0jgk"}}, 723 }, 724 { 725 Query: "INSERT INTO t1 VALUES (1);", 726 Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, 727 }, 728 { 729 Query: "SELECT dolt_hashof_table('t1');", 730 Expected: []sql.Row{{"a2vkt9d1mtuhd90opbcseo5gqjae7tv6"}}, 731 }, 732 { 733 Query: "SELECT dolt_hashof_table('noexist');", 734 ExpectedErrStr: "table not found: noexist", 735 }, 736 }, 737 }, 738 { 739 // https://github.com/dolthub/dolt/issues/7384 740 Name: "multiple unresolved foreign keys can be created on the same table", 741 SetUpScript: []string{ 742 "SET @@FOREIGN_KEY_CHECKS=0;", 743 "create table t1(pk int primary key);", 744 }, 745 Assertions: []queries.ScriptTestAssertion{ 746 { 747 Query: "create table t2 (pk int primary key, c1 int, c2 int, " + 748 "FOREIGN KEY (`c1`) REFERENCES `t1` (`pk`) ON DELETE CASCADE ON UPDATE CASCADE, " + 749 "FOREIGN KEY (`c2`) REFERENCES `t1` (`pk`) ON DELETE CASCADE ON UPDATE CASCADE);", 750 Expected: []sql.Row{{types.NewOkResult(0)}}, 751 }, 752 }, 753 }, 754 { 755 Name: "test has_ancestor", 756 SetUpScript: []string{ 757 "create table xy (x int primary key)", 758 "call dolt_commit('-Am', 'create')", 759 "set @main1 = hashof('HEAD');", 760 "insert into xy values (0)", 761 "call dolt_commit('-Am', 'add 0')", 762 "set @main2 = hashof('HEAD');", 763 "call dolt_branch('bone', @main1)", 764 "call dolt_checkout('bone')", 765 "insert into xy values (1)", 766 "call dolt_commit('-Am', 'add 1')", 767 "set @bone1 = hashof('HEAD');", 768 "insert into xy values (2)", 769 "call dolt_commit('-Am', 'add 2')", 770 "set @bone2 = hashof('HEAD');", 771 "call dolt_branch('btwo', @main1)", 772 "call dolt_checkout('btwo')", 773 "insert into xy values (3)", 774 "call dolt_commit('-Am', 'add 3')", 775 "set @btwo1 = hashof('HEAD');", 776 "call dolt_tag('tag_btwo1')", 777 "call dolt_checkout('main')", 778 "insert into xy values (4)", 779 "call dolt_commit('-Am', 'add 4')", 780 "set @main3 = hashof('HEAD');", 781 "call dolt_branch('onetwo', @bone2)", 782 "call dolt_checkout('onetwo')", 783 "call dolt_merge('btwo')", 784 "set @onetwo1 = hashof('HEAD');", 785 "call dolt_checkout('bone')", 786 }, 787 Assertions: []queries.ScriptTestAssertion{ 788 { 789 Query: "select has_ancestor('main', @main1), has_ancestor('main', @main2), has_ancestor('main', @bone1), has_ancestor('main', @bone2), has_ancestor('main', @btwo1), has_ancestor('main', @onetwo1), has_ancestor('main', 'HEAD')", 790 Expected: []sql.Row{{true, true, false, false, false, false, false}}, 791 }, 792 { 793 Query: "select has_ancestor('bone', @main1), has_ancestor('bone', @main2), has_ancestor('bone', @bone1), has_ancestor('bone', @bone2), has_ancestor('bone', @btwo1), has_ancestor('bone', @onetwo1), has_ancestor('bone', 'HEAD')", 794 Expected: []sql.Row{{true, false, true, true, false, false, true}}, 795 }, 796 { 797 Query: "select has_ancestor('btwo', @main1), has_ancestor('btwo', @main2), has_ancestor('btwo', @bone1), has_ancestor('btwo', @bone2), has_ancestor('btwo', @btwo1), has_ancestor('btwo', @onetwo1), has_ancestor('btwo', 'HEAD')", 798 Expected: []sql.Row{{true, false, false, false, true, false, false}}, 799 }, 800 { 801 Query: "select has_ancestor('onetwo', @main1), has_ancestor('onetwo', @main2), has_ancestor('onetwo', @bone1), has_ancestor('onetwo', @bone2), has_ancestor('onetwo', @btwo1), has_ancestor('onetwo', @onetwo1), has_ancestor('onetwo', 'HEAD')", 802 Expected: []sql.Row{{true, false, true, true, true, true, true}}, 803 }, 804 { 805 Query: "select has_ancestor(commit_hash, 'btwo') from dolt_log where commit_hash = @onetwo1", 806 Expected: []sql.Row{}, 807 }, 808 { 809 Query: "select has_ancestor(commit_hash, 'btwo') from dolt_log as of 'onetwo' where commit_hash = @onetwo1", 810 Expected: []sql.Row{{true}}, 811 }, 812 { 813 Query: "select has_ancestor('HEAD', 'tag_btwo1'), has_ancestor(@bone2, 'tag_btwo1'),has_ancestor(@onetwo1, 'tag_btwo1'), has_ancestor(@btwo1, 'tag_btwo1'), has_ancestor(@main2, 'tag_btwo1'), has_ancestor(@main1, 'tag_btwo1')", 814 Expected: []sql.Row{{false, false, true, true, false, false}}, 815 }, 816 { 817 Query: "select has_ancestor('tag_btwo1', 'HEAD'), has_ancestor('tag_btwo1', @bone2), has_ancestor('tag_btwo1', @onetwo1), has_ancestor('tag_btwo1', @btwo1), has_ancestor('tag_btwo1', @main2), has_ancestor('tag_btwo1', @main1)", 818 Expected: []sql.Row{{false, false, false, true, false, true}}, 819 }, 820 { 821 Query: "use `mydb/onetwo`;", 822 }, 823 { 824 Query: "select has_ancestor(commit_hash, 'btwo') from dolt_log where commit_hash = @onetwo1", 825 Expected: []sql.Row{{true}}, 826 }, 827 }, 828 }, 829 { 830 Name: "test null filtering in secondary indexes (https://github.com/dolthub/dolt/issues/4199)", 831 SetUpScript: []string{ 832 "create table t (pk int primary key auto_increment, d datetime, index index1 (d));", 833 "insert into t (d) values (NOW()), (NOW());", 834 "insert into t (d) values (NULL), (NULL);", 835 }, 836 Assertions: []queries.ScriptTestAssertion{ 837 { 838 Query: "select count(*) from t where d is not null", 839 Expected: []sql.Row{{2}}, 840 }, 841 { 842 Query: "select count(*) from t where d is null", 843 Expected: []sql.Row{{2}}, 844 }, 845 { 846 // Test the null-safe equals operator 847 Query: "select count(*) from t where d <=> NULL", 848 Expected: []sql.Row{{2}}, 849 }, 850 { 851 // Test the null-safe equals operator 852 Query: "select count(*) from t where not(d <=> null)", 853 Expected: []sql.Row{{2}}, 854 }, 855 { 856 // Test an IndexedJoin 857 Query: "select count(ifnull(t.d, 1)) from t, t as t2 where t.d is not null and t.pk = t2.pk and t2.d is not null;", 858 Expected: []sql.Row{{2}}, 859 }, 860 { 861 // Test an IndexedJoin 862 Query: "select count(ifnull(t.d, 1)) from t, t as t2 where t.d is null and t.pk = t2.pk and t2.d is null;", 863 Expected: []sql.Row{{2}}, 864 }, 865 { 866 // Test an IndexedJoin 867 Query: "select count(ifnull(t.d, 1)) from t, t as t2 where t.d is null and t.pk = t2.pk and t2.d is not null;", 868 Expected: []sql.Row{{0}}, 869 }, 870 }, 871 }, 872 { 873 Name: "test backticks in index name (https://github.com/dolthub/dolt/issues/3776)", 874 SetUpScript: []string{ 875 "create table t (pk int primary key, c1 int)", 876 }, 877 Assertions: []queries.ScriptTestAssertion{ 878 { 879 Query: "alter table t add index ```i```(c1);", 880 Expected: []sql.Row{{types.OkResult{}}}, 881 }, 882 { 883 Query: "show create table t;", 884 Expected: []sql.Row{{"t", 885 "CREATE TABLE `t` (\n" + 886 " `pk` int NOT NULL,\n" + 887 " `c1` int,\n" + 888 " PRIMARY KEY (`pk`),\n" + 889 " KEY ```i``` (`c1`)\n" + 890 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 891 }, 892 }, 893 }, 894 { 895 Name: "test AS OF indexed queries (https://github.com/dolthub/dolt/issues/7488)", 896 SetUpScript: []string{ 897 "create table indexedTable (pk int primary key, c0 int, c1 varchar(255), key c1_idx(c1));", 898 "insert into indexedTable (pk, c1) values (1, 'one');", 899 "call dolt_commit('-Am', 'adding table t with index');", 900 "SET @commit1 = hashof('HEAD');", 901 902 "update indexedTable set c1='two';", 903 "call dolt_commit('-am', 'updating one to two');", 904 "SET @commit2 = hashof('HEAD');", 905 }, 906 Assertions: []queries.ScriptTestAssertion{ 907 { 908 Query: "SELECT c1 from indexedTable;", 909 Expected: []sql.Row{{"two"}}, 910 ExpectedIndexes: []string{}, 911 }, 912 { 913 Query: "SELECT c1 from indexedTable where c1 > 'o';", 914 Expected: []sql.Row{{"two"}}, 915 ExpectedIndexes: []string{"c1_idx"}, 916 }, 917 { 918 Query: "SELECT c1 from indexedTable as of @commit2;", 919 Expected: []sql.Row{{"two"}}, 920 ExpectedIndexes: []string{}, 921 }, 922 { 923 Query: "SELECT c1 from indexedTable as of @commit2 where c1 > 'o';", 924 Expected: []sql.Row{{"two"}}, 925 ExpectedIndexes: []string{"c1_idx"}, 926 }, 927 { 928 Query: "SELECT c1 from indexedTable as of @commit1;", 929 Expected: []sql.Row{{"one"}}, 930 ExpectedIndexes: []string{}, 931 }, 932 { 933 Query: "SELECT c1 from indexedTable as of @commit1 where c1 > 'o';", 934 Expected: []sql.Row{{"one"}}, 935 ExpectedIndexes: []string{"c1_idx"}, 936 }, 937 }, 938 }, 939 { 940 Name: "test as of indexed join (https://github.com/dolthub/dolt/issues/2189)", 941 SetUpScript: []string{ 942 "create table a (pk int primary key, c1 int)", 943 "call DOLT_ADD('.')", 944 "insert into a values (1,1), (2,2), (3,3)", 945 "CALL DOLT_COMMIT('-a', '-m', 'first commit')", 946 "insert into a values (4,4), (5,5), (6,6)", 947 "CALL DOLT_COMMIT('-a', '-m', 'second commit')", 948 "set @second_commit = (select commit_hash from dolt_log order by date desc limit 1)", 949 "set @first_commit = (select commit_hash from dolt_log order by date desc limit 1,1)", 950 }, 951 Assertions: []queries.ScriptTestAssertion{ 952 { 953 Query: "select a1.* from a as of @second_commit a1 " + 954 "left join a as of @first_commit a2 on a1.pk = a2.pk where a2.pk is null order by 1", 955 Expected: []sql.Row{ 956 {4, 4}, 957 {5, 5}, 958 {6, 6}, 959 }, 960 }, 961 { 962 Query: "select a1.* from a as of @second_commit a1 " + 963 "left join a as of @second_commit a2 on a1.pk = a2.pk where a2.pk is null order by 1", 964 Expected: []sql.Row{}, 965 }, 966 }, 967 }, 968 { 969 Name: "Show create table with various keys and constraints", 970 SetUpScript: []string{ 971 "create table t1(a int primary key, b varchar(10) not null default 'abc')", 972 "alter table t1 add constraint ck1 check (b like '%abc%')", 973 "create index t1b on t1(b)", 974 "create table t2(c int primary key, d varchar(10))", 975 "alter table t2 add constraint fk1 foreign key (d) references t1 (b)", 976 "alter table t2 add constraint t2du unique (d)", 977 }, 978 Assertions: []queries.ScriptTestAssertion{ 979 { 980 Query: "show create table t1", 981 Expected: []sql.Row{ 982 {"t1", "CREATE TABLE `t1` (\n" + 983 " `a` int NOT NULL,\n" + 984 " `b` varchar(10) NOT NULL DEFAULT 'abc',\n" + 985 " PRIMARY KEY (`a`),\n" + 986 " KEY `t1b` (`b`),\n" + 987 " CONSTRAINT `ck1` CHECK (`b` LIKE '%abc%')\n" + 988 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, 989 }, 990 }, 991 { 992 Query: "show create table t2", 993 Expected: []sql.Row{ 994 {"t2", "CREATE TABLE `t2` (\n" + 995 " `c` int NOT NULL,\n" + 996 " `d` varchar(10),\n" + 997 " PRIMARY KEY (`c`),\n" + 998 " UNIQUE KEY `t2du` (`d`),\n" + 999 " CONSTRAINT `fk1` FOREIGN KEY (`d`) REFERENCES `t1` (`b`)\n" + 1000 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, 1001 }, 1002 }, 1003 }, 1004 }, 1005 { 1006 Name: "Query table with 10K rows ", 1007 SetUpScript: []string{ 1008 "create table bigTable (pk int primary key, c0 int);", 1009 makeLargeInsert(10_000), 1010 }, 1011 Assertions: []queries.ScriptTestAssertion{ 1012 { 1013 Query: "select count(*) from bigTable;", 1014 Expected: []sql.Row{ 1015 {int32(10_000)}, 1016 }, 1017 }, 1018 { 1019 Query: "select * from bigTable order by pk limit 5 offset 9990;", 1020 Expected: []sql.Row{ 1021 {int64(9990), int64(9990)}, 1022 {int64(9991), int64(9991)}, 1023 {int64(9992), int64(9992)}, 1024 {int64(9993), int64(9993)}, 1025 {int64(9994), int64(9994)}, 1026 }, 1027 }, 1028 }, 1029 }, 1030 { 1031 Name: "SHOW CREATE PROCEDURE works with Dolt external procedures", 1032 Assertions: []queries.ScriptTestAssertion{ 1033 { 1034 Query: "SHOW CREATE PROCEDURE dolt_checkout;", 1035 Expected: []sql.Row{ 1036 { 1037 "dolt_checkout", 1038 "", 1039 "CREATE PROCEDURE dolt_checkout() SELECT 'External stored procedure';", 1040 "utf8mb4", 1041 "utf8mb4_0900_bin", 1042 "utf8mb4_0900_bin", 1043 }, 1044 }, 1045 }, 1046 }, 1047 }, 1048 { 1049 Name: "Prepared ASOF", 1050 SetUpScript: []string{ 1051 "set @Commit1 = '';", 1052 "set @Commit2 = '';", 1053 "create table test (pk int primary key, c1 int)", 1054 "call dolt_add('.')", 1055 "insert into test values (0,0), (1,1);", 1056 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table');", 1057 "call dolt_branch('-c', 'main', 'newb')", 1058 "alter table test add column c2 int;", 1059 "call dolt_commit_hash_out(@Commit2, '-am', 'alter table');", 1060 }, 1061 Assertions: []queries.ScriptTestAssertion{ 1062 { 1063 Query: "select * from test as of 'HEAD~' where pk=?;", 1064 Expected: []sql.Row{{0, 0}}, 1065 Bindings: map[string]*query.BindVariable{ 1066 "v1": sqltypes.Int8BindVariable(int8(0)), 1067 }, 1068 }, 1069 { 1070 Query: "select * from test as of hashof('HEAD') where pk=?;", 1071 Expected: []sql.Row{{1, 1, nil}}, 1072 Bindings: map[string]*query.BindVariable{ 1073 "v1": sqltypes.Int8BindVariable(int8(1)), 1074 }, 1075 }, 1076 { 1077 Query: "select * from test as of @Commit1 where pk=?;", 1078 Expected: []sql.Row{{0, 0}}, 1079 Bindings: map[string]*query.BindVariable{ 1080 "v1": sqltypes.Int8BindVariable(int8(0)), 1081 }, 1082 }, 1083 { 1084 Query: "select * from test as of @Commit2 where pk=?;", 1085 Expected: []sql.Row{{0, 0, nil}}, 1086 Bindings: map[string]*query.BindVariable{ 1087 "v1": sqltypes.Int8BindVariable(int8(0)), 1088 }, 1089 }, 1090 }, 1091 }, 1092 { 1093 Name: "blame: composite pk ordered output with correct header (bats repro)", 1094 SetUpScript: []string{ 1095 "CREATE TABLE t(pk varchar(20), val int)", 1096 "ALTER TABLE t ADD PRIMARY KEY (pk, val)", 1097 "INSERT INTO t VALUES ('zzz',4),('mult',1),('sub',2),('add',5)", 1098 "CALL dolt_commit('-Am', 'add rows');", 1099 "INSERT INTO t VALUES ('dolt',0),('alt',12),('del',8),('ctl',3)", 1100 "CALL dolt_commit('-am', 'add more rows');", 1101 }, 1102 Assertions: []queries.ScriptTestAssertion{ 1103 { 1104 Query: "SELECT pk, val, message FROM dolt_blame_t", 1105 Expected: []sql.Row{ 1106 {"add", 5, "add rows"}, 1107 {"alt", 12, "add more rows"}, 1108 {"ctl", 3, "add more rows"}, 1109 {"del", 8, "add more rows"}, 1110 {"dolt", 0, "add more rows"}, 1111 {"mult", 1, "add rows"}, 1112 {"sub", 2, "add rows"}, 1113 {"zzz", 4, "add rows"}, 1114 }, 1115 }, 1116 }, 1117 }, 1118 { 1119 Name: "blame: table and pk require identifier quoting", 1120 SetUpScript: []string{ 1121 "create table `t-1` (`p-k` int primary key, col1 varchar(100));", 1122 "insert into `t-1` values (1, 'one');", 1123 "CALL dolt_commit('-Am', 'adding table t-1');", 1124 "insert into `t-1` values (2, 'two');", 1125 "CALL dolt_commit('-Am', 'adding another row to t-1');", 1126 }, 1127 Assertions: []queries.ScriptTestAssertion{ 1128 { 1129 Query: "SELECT `p-k`, message FROM `dolt_blame_t-1`;", 1130 Expected: []sql.Row{ 1131 {1, "adding table t-1"}, 1132 {2, "adding another row to t-1"}, 1133 }, 1134 }, 1135 }, 1136 }, 1137 { 1138 Name: "Nautobot FOREIGN KEY panic repro", 1139 SetUpScript: []string{ 1140 "CREATE TABLE `auth_user` (" + 1141 " `password` varchar(128) NOT NULL," + 1142 " `last_login` datetime," + 1143 " `is_superuser` tinyint NOT NULL," + 1144 " `username` varchar(150) NOT NULL," + 1145 " `first_name` varchar(150) NOT NULL," + 1146 " `last_name` varchar(150) NOT NULL," + 1147 " `email` varchar(254) NOT NULL," + 1148 " `is_staff` tinyint NOT NULL," + 1149 " `is_active` tinyint NOT NULL," + 1150 " `date_joined` datetime NOT NULL," + 1151 " `id` char(32) NOT NULL," + 1152 " `config_data` json NOT NULL," + 1153 " PRIMARY KEY (`id`)," + 1154 " UNIQUE KEY `username` (`username`)" + 1155 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin", 1156 "CREATE TABLE `users_token` (" + 1157 " `id` char(32) NOT NULL," + 1158 " `created` datetime NOT NULL," + 1159 " `expires` datetime," + 1160 " `key` varchar(40) NOT NULL," + 1161 " `write_enabled` tinyint NOT NULL," + 1162 " `description` varchar(200) NOT NULL," + 1163 " `user_id` char(32) NOT NULL," + 1164 " PRIMARY KEY (`id`)," + 1165 " UNIQUE KEY `key` (`key`)," + 1166 " KEY `users_token_user_id_af964690` (`user_id`)," + 1167 " CONSTRAINT `users_token_user_id_af964690_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`)" + 1168 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", 1169 "INSERT INTO `auth_user` (`password`,`last_login`,`is_superuser`,`username`,`first_name`,`last_name`,`email`,`is_staff`,`is_active`,`date_joined`,`id`,`config_data`)" + 1170 "VALUES ('pbkdf2_sha256$216000$KRpZeDPgwc5E$vl/2hwrmtnckaBT0A8pf63Ph+oYuCHYI7qozMTZihTo=',NULL,1,'admin','','','admin@example.com',1,1,'2022-08-30 18:27:21.810049','1056443cc03446c592fa4c06bb06a1a6','{}');", 1171 }, 1172 Assertions: []queries.ScriptTestAssertion{ 1173 { 1174 Query: "INSERT INTO `users_token` (`id`, `user_id`, `created`, `expires`, `key`, `write_enabled`, `description`) " + 1175 "VALUES ('acc2e157db2845a79221cc654b1dcecc', '1056443cc03446c592fa4c06bb06a1a6', '2022-08-30 18:27:21.948487', NULL, '0123456789abcdef0123456789abcdef01234567', 1, '');", 1176 Expected: []sql.Row{{types.OkResult{RowsAffected: 0x1, InsertID: 0x0}}}, 1177 }, 1178 }, 1179 }, 1180 { 1181 Name: "dolt_schemas schema", 1182 SetUpScript: []string{ 1183 "CREATE TABLE viewtest(v1 int, v2 int)", 1184 "CREATE VIEW view1 AS SELECT v1 FROM viewtest", 1185 "CREATE VIEW view2 AS SELECT v2 FROM viewtest", 1186 }, 1187 Assertions: []queries.ScriptTestAssertion{ 1188 { 1189 Query: "SELECT type, name, fragment FROM dolt_schemas ORDER BY 1, 2", 1190 Expected: []sql.Row{ 1191 {"view", "view1", "CREATE VIEW view1 AS SELECT v1 FROM viewtest"}, 1192 {"view", "view2", "CREATE VIEW view2 AS SELECT v2 FROM viewtest"}, 1193 }, 1194 }, 1195 { 1196 Query: "CREATE VIEW VIEW1 AS SELECT v2 FROM viewtest", 1197 ExpectedErr: sql.ErrExistingView, 1198 }, 1199 { 1200 Query: "drop view view1", 1201 SkipResultsCheck: true, 1202 }, 1203 { 1204 Query: "SELECT type, name, fragment FROM dolt_schemas ORDER BY 1, 2", 1205 Expected: []sql.Row{ 1206 {"view", "view2", "CREATE VIEW view2 AS SELECT v2 FROM viewtest"}, 1207 }, 1208 }, 1209 { 1210 Query: "CREATE VIEW VIEW1 AS SELECT v1 FROM viewtest", 1211 SkipResultsCheck: true, 1212 }, 1213 { 1214 Query: "SELECT type, name, fragment FROM dolt_schemas ORDER BY 1, 2", 1215 Expected: []sql.Row{ 1216 {"view", "view1", "CREATE VIEW VIEW1 AS SELECT v1 FROM viewtest"}, 1217 {"view", "view2", "CREATE VIEW view2 AS SELECT v2 FROM viewtest"}, 1218 }, 1219 }, 1220 }, 1221 }, 1222 { 1223 Name: "test hashof", 1224 SetUpScript: []string{ 1225 "CREATE TABLE hashof_test (pk int primary key, c1 int)", 1226 "INSERT INTO hashof_test values (1,1), (2,2), (3,3)", 1227 "CALL DOLT_ADD('hashof_test')", 1228 "CALL DOLT_COMMIT('-a', '-m', 'first commit')", 1229 "SET @Commit1 = (SELECT commit_hash FROM DOLT_LOG() LIMIT 1)", 1230 "INSERT INTO hashof_test values (4,4), (5,5), (6,6)", 1231 "CALL DOLT_COMMIT('-a', '-m', 'second commit')", 1232 "SET @Commit2 = (SELECT commit_hash from DOLT_LOG() LIMIT 1)", 1233 }, 1234 Assertions: []queries.ScriptTestAssertion{ 1235 { 1236 Query: "SELECT (hashof(@Commit1) = hashof(@Commit2))", 1237 Expected: []sql.Row{{false}}, 1238 }, 1239 { 1240 Query: "SELECT (hashof(@Commit1) = hashof('HEAD~1'))", 1241 Expected: []sql.Row{ 1242 {true}, 1243 }, 1244 }, 1245 { 1246 Query: "SELECT (hashof(@Commit2) = hashof('HEAD'))", 1247 Expected: []sql.Row{ 1248 {true}, 1249 }, 1250 }, 1251 { 1252 Query: "SELECT (hashof(@Commit2) = hashof('main'))", 1253 Expected: []sql.Row{ 1254 {true}, 1255 }, 1256 }, 1257 { 1258 Query: "SELECT hashof('non_branch')", 1259 ExpectedErrStr: "invalid ref spec", 1260 }, 1261 { 1262 // Test that a short commit is invalid. This may change in the future. 1263 Query: "SELECT hashof(left(@Commit2,30))", 1264 ExpectedErrStr: "invalid ref spec", 1265 }, 1266 }, 1267 }, 1268 } 1269 1270 func makeLargeInsert(sz int) string { 1271 var sb strings.Builder 1272 sb.WriteString("insert into bigTable values (0,0)") 1273 for i := 1; i < sz; i++ { 1274 sb.WriteString(fmt.Sprintf(",(%d,%d)", i, i)) 1275 } 1276 sb.WriteString(";") 1277 return sb.String() 1278 } 1279 1280 // DoltUserPrivTests are tests for Dolt-specific functionality that includes privilege checking logic. 1281 var DoltUserPrivTests = []queries.UserPrivilegeTest{ 1282 { 1283 Name: "dolt_purge_dropped_databases() privilege checking", 1284 SetUpScript: []string{ 1285 "create database mydb2;", 1286 "DROP DATABASE mydb2;", 1287 "CREATE USER tester@localhost;", 1288 "CREATE DATABASE other;", 1289 "GRANT EXECUTE ON *.* TO tester@localhost;", 1290 }, 1291 Assertions: []queries.UserPrivilegeTestAssertion{ 1292 { 1293 // Users without SUPER privilege cannot execute dolt_purge_dropped_databases 1294 User: "tester", 1295 Host: "localhost", 1296 Query: "call dolt_purge_dropped_databases;", 1297 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1298 }, 1299 { 1300 // Grant SUPER privileges to tester 1301 User: "root", 1302 Host: "localhost", 1303 Query: "GRANT SUPER ON *.* TO tester@localhost;", 1304 Expected: []sql.Row{{types.NewOkResult(0)}}, 1305 }, 1306 { 1307 // Now that tester has SUPER privileges, they can execute dolt_purge_dropped_databases 1308 User: "tester", 1309 Host: "localhost", 1310 Query: "call dolt_purge_dropped_databases;", 1311 Expected: []sql.Row{{0}}, 1312 }, 1313 { 1314 // Since root has SUPER privileges, they can execute dolt_purge_dropped_databases 1315 User: "root", 1316 Host: "localhost", 1317 Query: "call dolt_purge_dropped_databases;", 1318 Expected: []sql.Row{{0}}, 1319 }, 1320 }, 1321 }, 1322 { 1323 Name: "table function privilege checking", 1324 SetUpScript: []string{ 1325 "CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY);", 1326 "CREATE TABLE mydb.test2 (pk BIGINT PRIMARY KEY);", 1327 "CALL DOLT_ADD('.')", 1328 "CALL DOLT_COMMIT('-am', 'creating tables test and test2');", 1329 "INSERT INTO mydb.test VALUES (1);", 1330 "CALL DOLT_COMMIT('-am', 'inserting into test');", 1331 "CREATE USER tester@localhost;", 1332 }, 1333 Assertions: []queries.UserPrivilegeTestAssertion{ 1334 { 1335 // Without access to the database, dolt_diff should fail with a database access error 1336 User: "tester", 1337 Host: "localhost", 1338 Query: "SELECT * FROM dolt_diff('main~', 'main', 'test');", 1339 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1340 }, 1341 { 1342 // Without access to the database, dolt_diff with dots should fail with a database access error 1343 User: "tester", 1344 Host: "localhost", 1345 Query: "SELECT * FROM dolt_diff('main~..main', 'test');", 1346 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1347 }, 1348 { 1349 // Without access to the database, dolt_diff_stat should fail with a database access error 1350 User: "tester", 1351 Host: "localhost", 1352 Query: "SELECT * FROM dolt_diff_stat('main~', 'main', 'test');", 1353 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1354 }, 1355 { 1356 // Without access to the database, dolt_diff_stat with dots should fail with a database access error 1357 User: "tester", 1358 Host: "localhost", 1359 Query: "SELECT * FROM dolt_diff_stat('main~..main', 'test');", 1360 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1361 }, 1362 { 1363 // Without access to the database, dolt_diff_summary should fail with a database access error 1364 User: "tester", 1365 Host: "localhost", 1366 Query: "SELECT * FROM dolt_diff_summary('main~', 'main', 'test');", 1367 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1368 }, 1369 { 1370 // Without access to the database, dolt_diff_summary with dots should fail with a database access error 1371 User: "tester", 1372 Host: "localhost", 1373 Query: "SELECT * FROM dolt_diff_summary('main~..main', 'test');", 1374 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1375 }, 1376 { 1377 // Without access to the database, dolt_patch should fail with a database access error 1378 User: "tester", 1379 Host: "localhost", 1380 Query: "SELECT * FROM dolt_patch('main~', 'main', 'test');", 1381 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1382 }, 1383 { 1384 // Without access to the database, dolt_patch with dots should fail with a database access error 1385 User: "tester", 1386 Host: "localhost", 1387 Query: "SELECT * FROM dolt_patch('main~..main', 'test');", 1388 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1389 }, 1390 { 1391 // Without access to the database, dolt_log should fail with a database access error 1392 User: "tester", 1393 Host: "localhost", 1394 Query: "SELECT * FROM dolt_log('main');", 1395 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1396 }, 1397 { 1398 // Grant single-table access to the underlying user table 1399 User: "root", 1400 Host: "localhost", 1401 Query: "GRANT SELECT ON mydb.test TO tester@localhost;", 1402 Expected: []sql.Row{{types.NewOkResult(0)}}, 1403 }, 1404 { 1405 // After granting access to mydb.test, dolt_diff should work 1406 User: "tester", 1407 Host: "localhost", 1408 Query: "SELECT COUNT(*) FROM dolt_diff('main~', 'main', 'test');", 1409 Expected: []sql.Row{{1}}, 1410 }, 1411 { 1412 // After granting access to mydb.test, dolt_diff with dots should work 1413 User: "tester", 1414 Host: "localhost", 1415 Query: "SELECT COUNT(*) FROM dolt_diff('main~..main', 'test');", 1416 Expected: []sql.Row{{1}}, 1417 }, 1418 { 1419 // With access to the db, but not the table, dolt_diff should fail 1420 User: "tester", 1421 Host: "localhost", 1422 Query: "SELECT * FROM dolt_diff('main~', 'main', 'test2');", 1423 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1424 }, 1425 { 1426 // With access to the db, but not the table, dolt_diff with dots should fail 1427 User: "tester", 1428 Host: "localhost", 1429 Query: "SELECT * FROM dolt_diff('main~..main', 'test2');", 1430 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1431 }, 1432 { 1433 // With access to the db, but not the table, dolt_diff_stat should fail 1434 User: "tester", 1435 Host: "localhost", 1436 Query: "SELECT * FROM dolt_diff_stat('main~', 'main', 'test2');", 1437 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1438 }, 1439 { 1440 // With access to the db, but not the table, dolt_diff_stat with dots should fail 1441 User: "tester", 1442 Host: "localhost", 1443 Query: "SELECT * FROM dolt_diff_stat('main~...main', 'test2');", 1444 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1445 }, 1446 { 1447 // With access to the db, dolt_diff_stat should fail for all tables if no access any of tables 1448 User: "tester", 1449 Host: "localhost", 1450 Query: "SELECT * FROM dolt_diff_stat('main~', 'main');", 1451 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1452 }, 1453 { 1454 // With access to the db, dolt_diff_stat with dots should fail for all tables if no access any of tables 1455 User: "tester", 1456 Host: "localhost", 1457 Query: "SELECT * FROM dolt_diff_stat('main~...main');", 1458 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1459 }, 1460 { 1461 // With access to the db, but not the table, dolt_diff_summary should fail 1462 User: "tester", 1463 Host: "localhost", 1464 Query: "SELECT * FROM dolt_diff_summary('main~', 'main', 'test2');", 1465 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1466 }, 1467 { 1468 // With access to the db, but not the table, dolt_diff_summary with dots should fail 1469 User: "tester", 1470 Host: "localhost", 1471 Query: "SELECT * FROM dolt_diff_summary('main~...main', 'test2');", 1472 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1473 }, 1474 { 1475 // With access to the db, dolt_diff_summary should fail for all tables if no access any of tables 1476 User: "tester", 1477 Host: "localhost", 1478 Query: "SELECT * FROM dolt_diff_summary('main~', 'main');", 1479 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1480 }, 1481 { 1482 // With access to the db, dolt_diff_summary with dots should fail for all tables if no access any of tables 1483 User: "tester", 1484 Host: "localhost", 1485 Query: "SELECT * FROM dolt_diff_summary('main~...main');", 1486 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1487 }, 1488 { 1489 // With access to the db, but not the table, dolt_patch should fail 1490 User: "tester", 1491 Host: "localhost", 1492 Query: "SELECT * FROM dolt_patch('main~', 'main', 'test2');", 1493 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1494 }, 1495 { 1496 // With access to the db, but not the table, dolt_patch with dots should fail 1497 User: "tester", 1498 Host: "localhost", 1499 Query: "SELECT * FROM dolt_patch('main~...main', 'test2');", 1500 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1501 }, 1502 { 1503 // With access to the db, dolt_patch should fail for all tables if no access any of tables 1504 User: "tester", 1505 Host: "localhost", 1506 Query: "SELECT * FROM dolt_patch('main~', 'main');", 1507 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1508 }, 1509 { 1510 // With access to the db, dolt_patch with dots should fail for all tables if no access any of tables 1511 User: "tester", 1512 Host: "localhost", 1513 Query: "SELECT * FROM dolt_patch('main~...main');", 1514 ExpectedErr: sql.ErrPrivilegeCheckFailed, 1515 }, 1516 { 1517 // Revoke select on mydb.test 1518 User: "root", 1519 Host: "localhost", 1520 Query: "REVOKE SELECT ON mydb.test from tester@localhost;", 1521 Expected: []sql.Row{{types.NewOkResult(0)}}, 1522 }, 1523 { 1524 // After revoking access, dolt_diff should fail 1525 User: "tester", 1526 Host: "localhost", 1527 Query: "SELECT * FROM dolt_diff('main~', 'main', 'test');", 1528 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1529 }, 1530 { 1531 // After revoking access, dolt_diff with dots should fail 1532 User: "tester", 1533 Host: "localhost", 1534 Query: "SELECT * FROM dolt_diff('main~..main', 'test');", 1535 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1536 }, 1537 { 1538 // Grant multi-table access for all of mydb 1539 User: "root", 1540 Host: "localhost", 1541 Query: "GRANT SELECT ON mydb.* to tester@localhost;", 1542 Expected: []sql.Row{{types.NewOkResult(0)}}, 1543 }, 1544 { 1545 // After granting access to the entire db, dolt_diff should work 1546 User: "tester", 1547 Host: "localhost", 1548 Query: "SELECT COUNT(*) FROM dolt_diff('main~', 'main', 'test');", 1549 Expected: []sql.Row{{1}}, 1550 }, 1551 { 1552 // After granting access to the entire db, dolt_diff should work 1553 User: "tester", 1554 Host: "localhost", 1555 Query: "SELECT COUNT(*) FROM dolt_diff('main~..main', 'test');", 1556 Expected: []sql.Row{{1}}, 1557 }, 1558 { 1559 // After granting access to the entire db, dolt_diff_stat should work 1560 User: "tester", 1561 Host: "localhost", 1562 Query: "SELECT COUNT(*) FROM dolt_diff_stat('main~', 'main');", 1563 Expected: []sql.Row{{1}}, 1564 }, 1565 { 1566 // After granting access to the entire db, dolt_diff_stat with dots should work 1567 User: "tester", 1568 Host: "localhost", 1569 Query: "SELECT COUNT(*) FROM dolt_diff_stat('main~...main');", 1570 Expected: []sql.Row{{1}}, 1571 }, 1572 { 1573 // After granting access to the entire db, dolt_diff_summary should work 1574 User: "tester", 1575 Host: "localhost", 1576 Query: "SELECT COUNT(*) FROM dolt_diff_summary('main~', 'main');", 1577 Expected: []sql.Row{{1}}, 1578 }, 1579 { 1580 // After granting access to the entire db, dolt_diff_summary with dots should work 1581 User: "tester", 1582 Host: "localhost", 1583 Query: "SELECT COUNT(*) FROM dolt_diff_summary('main~...main');", 1584 Expected: []sql.Row{{1}}, 1585 }, 1586 { 1587 // After granting access to the entire db, dolt_patch should work 1588 User: "tester", 1589 Host: "localhost", 1590 Query: "SELECT COUNT(*) FROM dolt_patch('main~', 'main');", 1591 Expected: []sql.Row{{1}}, 1592 }, 1593 { 1594 // After granting access to the entire db, dolt_patch with dots should work 1595 User: "tester", 1596 Host: "localhost", 1597 Query: "SELECT COUNT(*) FROM dolt_patch('main~...main');", 1598 Expected: []sql.Row{{1}}, 1599 }, 1600 { 1601 // After granting access to the entire db, dolt_log should work 1602 User: "tester", 1603 Host: "localhost", 1604 Query: "SELECT COUNT(*) FROM dolt_log('main');", 1605 Expected: []sql.Row{{4}}, 1606 }, 1607 { 1608 // Revoke multi-table access 1609 User: "root", 1610 Host: "localhost", 1611 Query: "REVOKE SELECT ON mydb.* from tester@localhost;", 1612 Expected: []sql.Row{{types.NewOkResult(0)}}, 1613 }, 1614 { 1615 // After revoking access, dolt_diff should fail 1616 User: "tester", 1617 Host: "localhost", 1618 Query: "SELECT * FROM dolt_diff('main~', 'main', 'test');", 1619 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1620 }, 1621 { 1622 // After revoking access, dolt_diff with dots should fail 1623 User: "tester", 1624 Host: "localhost", 1625 Query: "SELECT * FROM dolt_diff('main~...main', 'test');", 1626 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1627 }, 1628 { 1629 // After revoking access, dolt_diff_stat should fail 1630 User: "tester", 1631 Host: "localhost", 1632 Query: "SELECT * FROM dolt_diff_stat('main~', 'main', 'test');", 1633 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1634 }, 1635 { 1636 // After revoking access, dolt_diff_summary should fail 1637 User: "tester", 1638 Host: "localhost", 1639 Query: "SELECT * FROM dolt_diff_summary('main~', 'main', 'test');", 1640 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1641 }, 1642 { 1643 // After revoking access, dolt_patch should fail 1644 User: "tester", 1645 Host: "localhost", 1646 Query: "SELECT * FROM dolt_patch('main~', 'main', 'test');", 1647 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1648 }, 1649 { 1650 // After revoking access, dolt_log should fail 1651 User: "tester", 1652 Host: "localhost", 1653 Query: "SELECT * FROM dolt_log('main');", 1654 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1655 }, 1656 { 1657 // After revoking access, dolt_schema_diff should fail against table 'test' 1658 User: "tester", 1659 Host: "localhost", 1660 Query: "SELECT * FROM dolt_schema_diff('HEAD^','HEAD','test');", 1661 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1662 }, 1663 { 1664 // After revoking access, dolt_schema_diff should fail against the entire db 1665 User: "tester", 1666 Host: "localhost", 1667 Query: "SELECT * FROM dolt_schema_diff('HEAD^','HEAD');", 1668 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1669 }, 1670 { 1671 // Grant global access to *.* 1672 User: "root", 1673 Host: "localhost", 1674 Query: "GRANT SELECT ON *.* to tester@localhost;", 1675 Expected: []sql.Row{{types.NewOkResult(0)}}, 1676 }, 1677 { 1678 // After granting global access to *.*, dolt_diff should work 1679 User: "tester", 1680 Host: "localhost", 1681 Query: "SELECT COUNT(*) FROM dolt_diff('main~', 'main', 'test');", 1682 Expected: []sql.Row{{1}}, 1683 }, 1684 { 1685 // After granting global access to *.*, dolt_diff should work 1686 User: "tester", 1687 Host: "localhost", 1688 Query: "SELECT COUNT(*) FROM dolt_diff('main~...main', 'test');", 1689 Expected: []sql.Row{{1}}, 1690 }, 1691 { 1692 // Revoke global access 1693 User: "root", 1694 Host: "localhost", 1695 Query: "REVOKE ALL ON *.* from tester@localhost;", 1696 Expected: []sql.Row{{types.NewOkResult(0)}}, 1697 }, 1698 { 1699 // After revoking global access, dolt_diff should fail 1700 User: "tester", 1701 Host: "localhost", 1702 Query: "SELECT * FROM dolt_diff('main~', 'main', 'test');", 1703 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1704 }, 1705 { 1706 // After revoking global access, dolt_diff with dots should fail 1707 User: "tester", 1708 Host: "localhost", 1709 Query: "SELECT * FROM dolt_diff('main~..main', 'test');", 1710 ExpectedErr: sql.ErrDatabaseAccessDeniedForUser, 1711 }, 1712 }, 1713 }, 1714 } 1715 1716 // HistorySystemTableScriptTests contains working tests for both prepared and non-prepared 1717 var HistorySystemTableScriptTests = []queries.ScriptTest{ 1718 { 1719 Name: "empty table", 1720 SetUpScript: []string{ 1721 "create table t (n int, c varchar(20));", 1722 "call dolt_add('.')", 1723 "set @Commit1 = '';", 1724 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", 1725 }, 1726 Assertions: []queries.ScriptTestAssertion{ 1727 { 1728 Query: "select count(*) from DOLT_HISTORY_t;", 1729 Expected: []sql.Row{{0}}, 1730 }, 1731 }, 1732 }, 1733 { 1734 Name: "keyless table", 1735 SetUpScript: []string{ 1736 "create table foo1 (n int, de varchar(20));", 1737 "insert into foo1 values (1, 'Ein'), (2, 'Zwei'), (3, 'Drei');", 1738 "call dolt_add('.')", 1739 "set @Commit1 = '';", 1740 "call dolt_commit_hash_out(@Commit1, '-am', 'inserting into foo1', '--date', '2022-08-06T12:00:00');", 1741 1742 "update foo1 set de='Eins' where n=1;", 1743 "set @Commit2 = '';", 1744 "call dolt_commit_hash_out(@Commit2, '-am', 'updating data in foo1', '--date', '2022-08-06T12:00:01');", 1745 1746 "insert into foo1 values (4, 'Vier');", 1747 "set @Commit3 = '';", 1748 "call dolt_commit_hash_out(@Commit3, '-am', 'inserting data in foo1', '--date', '2022-08-06T12:00:02');", 1749 }, 1750 Assertions: []queries.ScriptTestAssertion{ 1751 { 1752 Query: "select count(*) from DOLT_HISTORY_foO1;", 1753 Expected: []sql.Row{{10}}, 1754 }, 1755 { 1756 Query: "select n, de from dolt_history_foo1 where commit_hash=@Commit1;", 1757 Expected: []sql.Row{{1, "Ein"}, {2, "Zwei"}, {3, "Drei"}}, 1758 }, 1759 { 1760 Query: "select n, de from dolt_history_Foo1 where commit_hash=@Commit2;", 1761 Expected: []sql.Row{{1, "Eins"}, {2, "Zwei"}, {3, "Drei"}}, 1762 }, 1763 { 1764 Query: "select n, de from dolt_history_foo1 where commit_hash=@Commit3;", 1765 Expected: []sql.Row{{1, "Eins"}, {2, "Zwei"}, {3, "Drei"}, {4, "Vier"}}, 1766 }, 1767 }, 1768 }, 1769 { 1770 Name: "primary key table: basic cases", 1771 SetUpScript: []string{ 1772 "create table t1 (n int primary key, de varchar(20));", 1773 "call dolt_add('.')", 1774 "insert into t1 values (1, 'Eins'), (2, 'Zwei'), (3, 'Drei');", 1775 "set @Commit1 = '';", 1776 "call dolt_commit_hash_out(@Commit1, '-am', 'inserting into t1', '--date', '2022-08-06T12:00:01');", 1777 1778 "alter table t1 add column fr varchar(20);", 1779 "insert into t1 values (4, 'Vier', 'Quatre');", 1780 "set @Commit2 = '';", 1781 "call dolt_commit_hash_out(@Commit2, '-am', 'adding column and inserting data in t1', '--date', '2022-08-06T12:00:02');", 1782 1783 "update t1 set fr='Un' where n=1;", 1784 "update t1 set fr='Deux' where n=2;", 1785 "set @Commit3 = '';", 1786 "call dolt_commit_hash_out(@Commit3, '-am', 'updating data in t1', '--date', '2022-08-06T12:00:03');", 1787 1788 "update t1 set de=concat(de, ', meine herren') where n>1;", 1789 "set @Commit4 = '';", 1790 "call dolt_commit_hash_out(@Commit4, '-am', 'be polite when you address a gentleman', '--date', '2022-08-06T12:00:04');", 1791 1792 "delete from t1 where n=2;", 1793 "set @Commit5 = '';", 1794 "call dolt_commit_hash_out(@Commit5, '-am', 'we don''t need the number 2', '--date', '2022-08-06T12:00:05');", 1795 }, 1796 Assertions: []queries.ScriptTestAssertion{ 1797 { 1798 Query: "select count(*) from Dolt_History_t1;", 1799 Expected: []sql.Row{{18}}, 1800 }, 1801 { 1802 Query: "select n, de, fr from dolt_history_T1 where commit_hash = @Commit1;", 1803 Expected: []sql.Row{{1, "Eins", nil}, {2, "Zwei", nil}, {3, "Drei", nil}}, 1804 }, 1805 { 1806 Query: "select de, fr from dolt_history_T1 where commit_hash = @Commit1;", 1807 Expected: []sql.Row{{"Eins", nil}, {"Zwei", nil}, {"Drei", nil}}, 1808 }, 1809 { 1810 Query: "select n, de, fr from dolt_history_T1 where commit_hash = @Commit2;", 1811 Expected: []sql.Row{{1, "Eins", nil}, {2, "Zwei", nil}, {3, "Drei", nil}, {4, "Vier", "Quatre"}}, 1812 }, 1813 { 1814 Query: "select n, de, fr from dolt_history_T1 where commit_hash = @Commit3;", 1815 Expected: []sql.Row{{1, "Eins", "Un"}, {2, "Zwei", "Deux"}, {3, "Drei", nil}, {4, "Vier", "Quatre"}}, 1816 }, 1817 { 1818 Query: "select n, de, fr from dolt_history_T1 where commit_hash = @Commit4;", 1819 Expected: []sql.Row{ 1820 {1, "Eins", "Un"}, 1821 {2, "Zwei, meine herren", "Deux"}, 1822 {3, "Drei, meine herren", nil}, 1823 {4, "Vier, meine herren", "Quatre"}, 1824 }, 1825 }, 1826 { 1827 Query: "select n, de, fr from dolt_history_T1 where commit_hash = @Commit5;", 1828 Expected: []sql.Row{ 1829 {1, "Eins", "Un"}, 1830 {3, "Drei, meine herren", nil}, 1831 {4, "Vier, meine herren", "Quatre"}, 1832 }, 1833 }, 1834 { 1835 Query: "select de, fr, commit_hash=@commit1, commit_hash=@commit2, commit_hash=@commit3, commit_hash=@commit4" + 1836 " from dolt_history_T1 where n=2 order by commit_date", 1837 Expected: []sql.Row{ 1838 {"Zwei", nil, true, false, false, false}, 1839 {"Zwei", nil, false, true, false, false}, 1840 {"Zwei", "Deux", false, false, true, false}, 1841 {"Zwei, meine herren", "Deux", false, false, false, true}, 1842 }, 1843 }, 1844 }, 1845 }, 1846 { 1847 Name: "index by primary key", 1848 SetUpScript: []string{ 1849 "create table t1 (pk int primary key, c int);", 1850 "call dolt_add('.')", 1851 "insert into t1 values (1,2), (3,4)", 1852 "set @Commit1 = '';", 1853 "call dolt_commit_hash_out(@Commit1, '-am', 'initial table');", 1854 "insert into t1 values (5,6), (7,8)", 1855 "set @Commit2 = '';", 1856 "call dolt_commit_hash_out(@Commit2, '-am', 'two more rows');", 1857 }, 1858 Assertions: []queries.ScriptTestAssertion{ 1859 { 1860 Query: "select pk, c, commit_hash = @Commit1, commit_hash = @Commit2 from dolt_history_t1", 1861 Expected: []sql.Row{ 1862 {1, 2, false, true}, 1863 {3, 4, false, true}, 1864 {5, 6, false, true}, 1865 {7, 8, false, true}, 1866 {1, 2, true, false}, 1867 {3, 4, true, false}, 1868 }, 1869 }, 1870 { 1871 Query: "select pk, c from dolt_history_t1 order by pk", 1872 Expected: []sql.Row{ 1873 {1, 2}, 1874 {1, 2}, 1875 {3, 4}, 1876 {3, 4}, 1877 {5, 6}, 1878 {7, 8}, 1879 }, 1880 }, 1881 { 1882 Query: "select pk, c from dolt_history_t1 order by pk, c", 1883 Expected: []sql.Row{ 1884 {1, 2}, 1885 {1, 2}, 1886 {3, 4}, 1887 {3, 4}, 1888 {5, 6}, 1889 {7, 8}, 1890 }, 1891 }, 1892 { 1893 Query: "select pk, c from dolt_history_t1 where pk = 3", 1894 Expected: []sql.Row{ 1895 {3, 4}, 1896 {3, 4}, 1897 }, 1898 }, 1899 { 1900 Query: "select pk, c from dolt_history_t1 where pk = 3 and commit_hash = @Commit2", 1901 Expected: []sql.Row{ 1902 {3, 4}, 1903 }, 1904 }, 1905 { 1906 Query: "explain select pk, c from dolt_history_t1 where pk = 3", 1907 Expected: []sql.Row{ 1908 {"Filter"}, 1909 {" ├─ (dolt_history_t1.pk = 3)"}, 1910 {" └─ IndexedTableAccess(dolt_history_t1)"}, 1911 {" ├─ index: [dolt_history_t1.pk]"}, 1912 {" ├─ filters: [{[3, 3]}]"}, 1913 {" └─ columns: [pk c]"}, 1914 }, 1915 }, 1916 { 1917 Query: "explain select pk, c from dolt_history_t1 where pk = 3 and committer = 'someguy'", 1918 Expected: []sql.Row{ 1919 {"Project"}, 1920 {" ├─ columns: [dolt_history_t1.pk, dolt_history_t1.c]"}, 1921 {" └─ Filter"}, 1922 {" ├─ ((dolt_history_t1.pk = 3) AND (dolt_history_t1.committer = 'someguy'))"}, 1923 {" └─ IndexedTableAccess(dolt_history_t1)"}, 1924 {" ├─ index: [dolt_history_t1.pk]"}, 1925 {" ├─ filters: [{[3, 3]}]"}, 1926 {" └─ columns: [pk c committer]"}, 1927 }, 1928 }, 1929 }, 1930 }, 1931 { 1932 Name: "adding an index", 1933 SetUpScript: []string{ 1934 "create table t1 (pk int primary key, c int);", 1935 "call dolt_add('.')", 1936 "insert into t1 values (1,2), (3,4)", 1937 "set @Commit1 = '';", 1938 "call dolt_commit_hash_out(@Commit1, '-am', 'initial table');", 1939 "insert into t1 values (5,6), (7,8)", 1940 "set @Commit2 = '';", 1941 "call dolt_commit_hash_out(@Commit2, '-am', 'two more rows');", 1942 "insert into t1 values (9,10), (11,12)", 1943 "create index t1_c on t1(c)", 1944 "set @Commit2 = '';", 1945 "call dolt_commit_hash_out(@Commit2, '-am', 'two more rows and an index');", 1946 }, 1947 Assertions: []queries.ScriptTestAssertion{ 1948 { 1949 Query: "select pk, c from dolt_history_t1 order by pk", 1950 Expected: []sql.Row{ 1951 {1, 2}, 1952 {1, 2}, 1953 {1, 2}, 1954 {3, 4}, 1955 {3, 4}, 1956 {3, 4}, 1957 {5, 6}, 1958 {5, 6}, 1959 {7, 8}, 1960 {7, 8}, 1961 {9, 10}, 1962 {11, 12}, 1963 }, 1964 }, 1965 { 1966 Query: "select pk, c from dolt_history_t1 where c = 4 order by pk", 1967 Expected: []sql.Row{ 1968 {3, 4}, 1969 {3, 4}, 1970 {3, 4}, 1971 }, 1972 }, 1973 { 1974 Query: "select pk, c from dolt_history_t1 where c = 10 order by pk", 1975 Expected: []sql.Row{ 1976 {9, 10}, 1977 }, 1978 }, 1979 { 1980 Query: "explain select pk, c from dolt_history_t1 where c = 4", 1981 Expected: []sql.Row{ 1982 {"Filter"}, 1983 {" ├─ (dolt_history_t1.c = 4)"}, 1984 {" └─ IndexedTableAccess(dolt_history_t1)"}, 1985 {" ├─ index: [dolt_history_t1.c]"}, 1986 {" ├─ filters: [{[4, 4]}]"}, 1987 {" └─ columns: [pk c]"}, 1988 }, 1989 }, 1990 { 1991 Query: "explain select pk, c from dolt_history_t1 where c = 10 and committer = 'someguy'", 1992 Expected: []sql.Row{ 1993 {"Project"}, 1994 {" ├─ columns: [dolt_history_t1.pk, dolt_history_t1.c]"}, 1995 {" └─ Filter"}, 1996 {" ├─ ((dolt_history_t1.c = 10) AND (dolt_history_t1.committer = 'someguy'))"}, 1997 {" └─ IndexedTableAccess(dolt_history_t1)"}, 1998 {" ├─ index: [dolt_history_t1.c]"}, 1999 {" ├─ filters: [{[10, 10]}]"}, 2000 {" └─ columns: [pk c committer]"}, 2001 }, 2002 }, 2003 }, 2004 }, 2005 { 2006 Name: "primary key table: non-pk column drops and adds", 2007 SetUpScript: []string{ 2008 "create table t (pk int primary key, c1 int, c2 varchar(20));", 2009 "call dolt_add('.')", 2010 "insert into t values (1, 2, '3'), (4, 5, '6');", 2011 "set @Commit1 = '';", 2012 "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", 2013 2014 "alter table t drop column c2;", 2015 "set @Commit2 = '';", 2016 "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c2');", 2017 2018 "alter table t rename column c1 to c2;", 2019 "set @Commit3 = '';", 2020 "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'renaming c1 to c2');", 2021 }, 2022 Assertions: []queries.ScriptTestAssertion{ 2023 { 2024 Query: "select count(*) from dolt_history_t;", 2025 Expected: []sql.Row{{6}}, 2026 }, 2027 { 2028 // TODO: Instead of just spot checking the non-existence of c1, it would be useful to be able to 2029 // assert the full schema of the result set. ScriptTestAssertion doesn't support that currently, 2030 // but the code from QueryTest could be ported over to ScriptTestAssertion. 2031 Query: "select c1 from dolt_history_t;", 2032 ExpectedErr: sql.ErrColumnNotFound, 2033 }, 2034 { 2035 Query: "select pk, c2 from dolt_history_t where commit_hash=@Commit1 order by pk;", 2036 Expected: []sql.Row{{1, nil}, {4, nil}}, 2037 }, 2038 { 2039 Query: "select pk, c2 from dolt_history_t where commit_hash=@Commit2 order by pk;", 2040 Expected: []sql.Row{{1, nil}, {4, nil}}, 2041 }, 2042 { 2043 Query: "select pk, c2 from dolt_history_t where commit_hash=@Commit3 order by pk;", 2044 Expected: []sql.Row{{1, 2}, {4, 5}}, 2045 }, 2046 }, 2047 }, 2048 { 2049 Name: "primary key table: non-pk column type changes", 2050 SetUpScript: []string{ 2051 "create table t (pk int primary key, c1 int, c2 varchar(20));", 2052 "CALL DOLT_COMMIT('-Am', 'creating table t');", 2053 "set @Commit1 = dolt_hashof('HEAD');", 2054 2055 "insert into t values (1, 2, '3'), (4, 5, '6');", 2056 "CALL DOLT_COMMIT('-Am', 'inserting two rows');", 2057 "set @Commit2 = dolt_hashof('HEAD');", 2058 2059 "CALL DOLT_COMMIT('--allow-empty', '-m', 'empty commit');", 2060 "set @Commit3 = dolt_hashof('HEAD');", 2061 2062 "alter table t modify column c2 int;", 2063 "CALL DOLT_COMMIT('-am', 'changed type of c2');", 2064 "set @Commit4 = dolt_hashof('HEAD');", 2065 }, 2066 Assertions: []queries.ScriptTestAssertion{ 2067 { 2068 Query: "select count(*) from dolt_history_t;", 2069 Expected: []sql.Row{{6}}, 2070 }, 2071 // Can't represent the old schema in the current one, so it gets nil valued 2072 { 2073 Query: "select pk, c2 from dolt_history_t where commit_hash=@Commit2 order by pk;", 2074 Expected: []sql.Row{{1, nil}, {4, nil}}, 2075 }, 2076 { 2077 Query: "select pk, c2 from dolt_history_t where commit_hash=@Commit4 order by pk;", 2078 Expected: []sql.Row{{1, 3}, {4, 6}}, 2079 }, 2080 { 2081 // When filtering on a column from the original table, we use the primary index here, but if column 2082 // tags have changed in previous versions of the table, the index tags won't match up completely. 2083 // https://github.com/dolthub/dolt/issues/6891 2084 // NOTE: {4,5,nil} shows up as a row from the first commit, when c2 was a varchar type. The schema 2085 // for dolt_history_t uses the current table schema, and we can't extract an int from the older 2086 // version's tuple, so it shows up as a NULL and a SQL warning in the session. In the future, 2087 // we could consider using a different tuple descriptor based on the version of the row and 2088 // pull the data out and try to convert it to the new type. 2089 Query: "select pk, c1, c2 from dolt_history_t where pk=4;", 2090 Expected: []sql.Row{{4, 5, 6}, {4, 5, nil}, {4, 5, nil}}, 2091 ExpectedWarning: 1246, 2092 ExpectedWarningsCount: 1, 2093 ExpectedWarningMessageSubstring: "Unable to convert field c2 in historical rows because " + 2094 "its type (int) doesn't match current schema's type (varchar(20))", 2095 }, 2096 }, 2097 }, 2098 { 2099 Name: "primary key table: rename table", 2100 SetUpScript: []string{ 2101 "create table t (pk int primary key, c1 int, c2 varchar(20));", 2102 "call dolt_add('.')", 2103 "insert into t values (1, 2, '3'), (4, 5, '6');", 2104 "set @Commit1 = '';", 2105 "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", 2106 2107 "alter table t rename to t2;", 2108 "call dolt_add('.')", 2109 "set @Commit2 = '';", 2110 "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'renaming table to t2');", 2111 }, 2112 Assertions: []queries.ScriptTestAssertion{ 2113 { 2114 Query: "select count(*) from dolt_history_t;", 2115 ExpectedErr: sql.ErrTableNotFound, 2116 }, 2117 { 2118 Query: "select count(*) from dolt_history_T2;", 2119 Expected: []sql.Row{{2}}, 2120 }, 2121 { 2122 Query: "select pk, c1, c2 from dolt_history_t2 where commit_hash != @Commit1;", 2123 Expected: []sql.Row{{1, 2, "3"}, {4, 5, "6"}}, 2124 }, 2125 }, 2126 }, 2127 { 2128 Name: "primary key table: delete and recreate table", 2129 SetUpScript: []string{ 2130 "create table t (pk int primary key, c1 int, c2 varchar(20));", 2131 "call dolt_add('.')", 2132 "insert into t values (1, 2, '3'), (4, 5, '6');", 2133 "set @Commit1 = '';", 2134 "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", 2135 2136 "drop table t;", 2137 "set @Commit2 = '';", 2138 "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping table t');", 2139 2140 "create table t (pk int primary key, c1 int);", 2141 "call dolt_add('.')", 2142 "set @Commit3 = '';", 2143 "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'recreating table t');", 2144 }, 2145 Assertions: []queries.ScriptTestAssertion{ 2146 { 2147 // TODO: The history system table processes history in parallel and pulls the rows for the 2148 // user table at all commits. This means we can't currently detect when a table was dropped 2149 // and if a different table with the same name exists at earlier commits, those results will 2150 // be included in the history table. It may make more sense to have history scoped only 2151 // to the current instance of the table, which would require changing the history system table 2152 // to use something like an iterator approach where it goes back sequentially until it detects 2153 // the current table doesn't exist any more and then stop. 2154 Query: "select count(*) from dolt_history_t;", 2155 Expected: []sql.Row{{2}}, 2156 }, 2157 }, 2158 }, 2159 { 2160 Name: "dolt_history table with AS OF", 2161 SetUpScript: []string{ 2162 "create table t (pk int primary key, c1 int, c2 varchar(20));", 2163 "call dolt_add('-A');", 2164 "call dolt_commit('-m', 'creating table t');", 2165 "insert into t values (1, 2, '3'), (4, 5, '6');", 2166 "call dolt_commit('-am', 'added values');", 2167 "insert into t values (11, 22, '3'), (44, 55, '6');", 2168 "call dolt_commit('-am', 'added values again');", 2169 }, 2170 Assertions: []queries.ScriptTestAssertion{ 2171 { 2172 Query: "select count(*) from dolt_history_t;", 2173 Expected: []sql.Row{{6}}, // 2 + 4 2174 }, 2175 { 2176 Query: "select count(*) from dolt_history_t AS OF 'head^';", 2177 Expected: []sql.Row{{2}}, // 2 2178 }, 2179 { 2180 Query: "select message from dolt_log;", 2181 Expected: []sql.Row{ 2182 {"added values again"}, 2183 {"added values"}, 2184 {"creating table t"}, 2185 {"checkpoint enginetest database mydb"}, 2186 {"Initialize data repository"}, 2187 }, 2188 }, 2189 }, 2190 }, 2191 { 2192 SkipPrepared: true, 2193 Name: "dolt_history table with AS OF", 2194 SetUpScript: []string{ 2195 "create table t (pk int primary key, c1 int, c2 varchar(20));", 2196 "call dolt_add('-A');", 2197 "call dolt_commit('-m', 'creating table t');", 2198 "insert into t values (1, 2, '3'), (4, 5, '6');", 2199 "call dolt_commit('-am', 'added values');", 2200 "insert into t values (11, 22, '3'), (44, 55, '6');", 2201 "call dolt_commit('-am', 'added values again');", 2202 }, 2203 Assertions: []queries.ScriptTestAssertion{ 2204 { 2205 Query: "select message from dolt_log AS OF 'head^';", 2206 Expected: []sql.Row{ 2207 {"added values"}, 2208 {"creating table t"}, 2209 {"checkpoint enginetest database mydb"}, 2210 {"Initialize data repository"}, 2211 }, 2212 }, 2213 }, 2214 }, 2215 { 2216 Name: "dolt_history table with enums", 2217 SetUpScript: []string{ 2218 "create table t (pk int primary key, c1 enum('foo','bar'));", 2219 "call dolt_add('-A');", 2220 "call dolt_commit('-m', 'creating table t');", 2221 "insert into t values (1, 'foo');", 2222 "call dolt_commit('-am', 'added values');", 2223 }, 2224 Assertions: []queries.ScriptTestAssertion{ 2225 { 2226 Query: "select c1 from dolt_history_t;", 2227 Expected: []sql.Row{ 2228 {"foo"}, 2229 }, 2230 }, 2231 }, 2232 }, 2233 { 2234 Name: "dolt_history table index lookup", 2235 SetUpScript: []string{ 2236 "create table yx (y int, x int primary key);", 2237 "call dolt_add('.');", 2238 "call dolt_commit('-m', 'creating table');", 2239 "insert into yx values (0, 1);", 2240 "call dolt_commit('-am', 'add data');", 2241 "insert into yx values (2, 3);", 2242 "call dolt_commit('-am', 'add data');", 2243 "insert into yx values (4, 5);", 2244 "call dolt_commit('-am', 'add data');", 2245 }, 2246 Assertions: []queries.ScriptTestAssertion{ 2247 { 2248 Query: "select count(x) from dolt_history_yx where x = 1;", 2249 Expected: []sql.Row{ 2250 {3}, 2251 }, 2252 }, 2253 }, 2254 }, 2255 { 2256 Name: "dolt_history table filter correctness", 2257 SetUpScript: []string{ 2258 "create table xy (x int primary key, y int);", 2259 "call dolt_add('.');", 2260 "call dolt_commit('-m', 'creating table');", 2261 "insert into xy values (0, 1);", 2262 "call dolt_commit('-am', 'add data');", 2263 "insert into xy values (2, 3);", 2264 "call dolt_commit('-am', 'add data');", 2265 "insert into xy values (4, 5);", 2266 "call dolt_commit('-am', 'add data');", 2267 }, 2268 Assertions: []queries.ScriptTestAssertion{ 2269 { 2270 Query: "select count(*) from dolt_history_xy where commit_hash = (select dolt_log.commit_hash from dolt_log limit 1 offset 1)", 2271 Expected: []sql.Row{ 2272 {2}, 2273 }, 2274 }, 2275 }, 2276 }, 2277 { 2278 Name: "dolt_history table primary key with join", 2279 SetUpScript: []string{ 2280 "create table xyz (x int, y int, z int, primary key(x, y));", 2281 "call dolt_add('.');", 2282 "call dolt_commit('-m', 'creating table');", 2283 "insert into xyz values (0, 1, 100);", 2284 "call dolt_commit('-am', 'add data');", 2285 "insert into xyz values (2, 3, 200);", 2286 "call dolt_commit('-am', 'add data');", 2287 "insert into xyz values (4, 5, 300);", 2288 "call dolt_commit('-am', 'add data');", 2289 }, 2290 Assertions: []queries.ScriptTestAssertion{ 2291 { 2292 2293 Query: ` 2294 SELECT 2295 dolt_history_xyz.x as x, 2296 dolt_history_xyz.y as y, 2297 dolt_history_xyz.z as z, 2298 dolt_commits.commit_hash as comm 2299 FROM 2300 dolt_history_xyz 2301 LEFT JOIN 2302 dolt_commits 2303 ON 2304 dolt_history_xyz.commit_hash = dolt_commits.commit_hash 2305 ORDER BY 2306 dolt_history_xyz.x, 2307 dolt_history_xyz.y, 2308 dolt_history_xyz.z;`, 2309 Expected: []sql.Row{ 2310 {0, 1, 100, doltCommit}, 2311 {0, 1, 100, doltCommit}, 2312 {0, 1, 100, doltCommit}, 2313 {2, 3, 200, doltCommit}, 2314 {2, 3, 200, doltCommit}, 2315 {4, 5, 300, doltCommit}, 2316 }, 2317 }, 2318 { 2319 Query: ` 2320 SELECT 2321 dolt_history_xyz.y as y, 2322 dolt_history_xyz.z as z, 2323 dolt_commits.commit_hash as comm 2324 FROM 2325 dolt_history_xyz 2326 LEFT JOIN 2327 dolt_commits 2328 ON 2329 dolt_history_xyz.commit_hash = dolt_commits.commit_hash 2330 ORDER BY 2331 dolt_history_xyz.y, 2332 dolt_history_xyz.z;`, 2333 Expected: []sql.Row{ 2334 {1, 100, doltCommit}, 2335 {1, 100, doltCommit}, 2336 {1, 100, doltCommit}, 2337 {3, 200, doltCommit}, 2338 {3, 200, doltCommit}, 2339 {5, 300, doltCommit}, 2340 }, 2341 }, 2342 { 2343 Query: ` 2344 SELECT 2345 dolt_history_xyz.z as z, 2346 dolt_commits.commit_hash as comm 2347 FROM 2348 dolt_history_xyz 2349 LEFT JOIN 2350 dolt_commits 2351 ON 2352 dolt_history_xyz.commit_hash = dolt_commits.commit_hash 2353 ORDER BY 2354 dolt_history_xyz.z;`, 2355 Expected: []sql.Row{ 2356 {100, doltCommit}, 2357 {100, doltCommit}, 2358 {100, doltCommit}, 2359 {200, doltCommit}, 2360 {200, doltCommit}, 2361 {300, doltCommit}, 2362 }, 2363 }, 2364 { 2365 Query: ` 2366 SELECT z 2367 FROM xyz 2368 WHERE z IN ( 2369 SELECT z 2370 FROM dolt_history_xyz 2371 LEFT JOIN dolt_commits 2372 ON dolt_history_xyz.commit_hash = dolt_commits.commit_hash 2373 );`, 2374 Expected: []sql.Row{ 2375 {100}, 2376 {200}, 2377 {300}, 2378 }, 2379 }, 2380 }, 2381 }, 2382 { 2383 Name: "can sort by dolt_log.commit", 2384 SetUpScript: []string{}, 2385 Assertions: []queries.ScriptTestAssertion{ 2386 { 2387 Query: "select 'something' from dolt_log order by commit_hash;", 2388 Expected: []sql.Row{ 2389 {"something"}, 2390 {"something"}, 2391 }, 2392 }, 2393 { 2394 Query: "select 'something' from dolt_diff order by commit_hash;", 2395 Expected: []sql.Row{}, 2396 }, 2397 { 2398 Query: "select 'something' from dolt_commits order by commit_hash;", 2399 Expected: []sql.Row{ 2400 {"something"}, 2401 {"something"}, 2402 }, 2403 }, 2404 { 2405 Query: "select 'something' from dolt_commit_ancestors order by commit_hash;", 2406 Expected: []sql.Row{ 2407 {"something"}, 2408 {"something"}, 2409 }, 2410 }, 2411 }, 2412 }, 2413 } 2414 2415 // BrokenHistorySystemTableScriptTests contains tests that work for non-prepared, but don't work 2416 // for prepared queries. 2417 var BrokenHistorySystemTableScriptTests = []queries.ScriptTest{ 2418 { 2419 Name: "dolt_history table with AS OF", 2420 SetUpScript: []string{ 2421 "create table t (pk int primary key, c1 int, c2 varchar(20));", 2422 "call dolt_add('-A');", 2423 "call dolt_commit('-m', 'creating table t');", 2424 "insert into t values (1, 2, '3'), (4, 5, '6');", 2425 "call dolt_commit('-am', 'added values');", 2426 "insert into t values (11, 22, '3'), (44, 55, '6');", 2427 "call dolt_commit('-am', 'added values again');", 2428 }, 2429 Assertions: []queries.ScriptTestAssertion{ 2430 { 2431 Query: "select message from dolt_log AS OF 'head^';", 2432 Expected: []sql.Row{ 2433 {"added values"}, 2434 {"creating table t"}, 2435 {"checkpoint enginetest database mydb"}, 2436 {"Initialize data repository"}, 2437 }, 2438 }, 2439 }, 2440 }, 2441 } 2442 2443 var DoltCheckoutScripts = []queries.ScriptTest{ 2444 { 2445 Name: "dolt_checkout changes working set", 2446 SetUpScript: []string{ 2447 "create table t (a int primary key, b int);", 2448 "call dolt_commit('-Am', 'creating table t');", 2449 "call dolt_branch('b2');", 2450 "call dolt_branch('b3');", 2451 "insert into t values (1, 1);", 2452 "call dolt_commit('-Am', 'added values on main');", 2453 "call dolt_checkout('b2');", 2454 "insert into t values (2, 2);", 2455 "call dolt_commit('-am', 'added values on b2');", 2456 "call dolt_checkout('b3');", 2457 "insert into t values (3, 3);", 2458 "call dolt_commit('-am', 'added values on b3');", 2459 "call dolt_checkout('main');", 2460 }, 2461 Assertions: []queries.ScriptTestAssertion{ 2462 { 2463 Query: "select active_branch();", 2464 Expected: []sql.Row{{"main"}}, 2465 }, 2466 { 2467 Query: "select * from t;", 2468 Expected: []sql.Row{{1, 1}}, 2469 }, 2470 { 2471 Query: "call dolt_checkout('b2');", 2472 SkipResultsCheck: true, 2473 }, 2474 { 2475 Query: "select active_branch();", 2476 Expected: []sql.Row{{"b2"}}, 2477 }, 2478 { 2479 Query: "select * from t;", 2480 Expected: []sql.Row{{2, 2}}, 2481 }, 2482 { 2483 Query: "call dolt_checkout('b3');", 2484 SkipResultsCheck: true, 2485 }, 2486 { 2487 Query: "select active_branch();", 2488 Expected: []sql.Row{{"b3"}}, 2489 }, 2490 { 2491 Query: "select * from t;", 2492 Expected: []sql.Row{{3, 3}}, 2493 }, 2494 { 2495 Query: "call dolt_checkout('main');", 2496 SkipResultsCheck: true, 2497 }, 2498 { 2499 Query: "select active_branch();", 2500 Expected: []sql.Row{{"main"}}, 2501 }, 2502 { 2503 Query: "select * from t;", 2504 Expected: []sql.Row{{1, 1}}, 2505 }, 2506 }, 2507 }, 2508 { 2509 Name: "dolt_checkout with new branch", 2510 SetUpScript: []string{ 2511 "create table t (a int primary key, b int);", 2512 "insert into t values (1, 1);", 2513 "call dolt_commit('-Am', 'creating table t');", 2514 "call dolt_checkout('-b', 'b2');", 2515 "insert into t values (2, 2);", 2516 "call dolt_commit('-am', 'added values on b2');", 2517 }, 2518 Assertions: []queries.ScriptTestAssertion{ 2519 { 2520 Query: "select active_branch();", 2521 Expected: []sql.Row{{"b2"}}, 2522 }, 2523 { 2524 Query: "call dolt_checkout('main');", 2525 SkipResultsCheck: true, 2526 }, 2527 { 2528 Query: "select * from t;", 2529 Expected: []sql.Row{{1, 1}}, 2530 }, 2531 { 2532 Query: "call dolt_checkout('b2');", 2533 SkipResultsCheck: true, 2534 }, 2535 { 2536 Query: "select active_branch();", 2537 Expected: []sql.Row{{"b2"}}, 2538 }, 2539 { 2540 Query: "select * from t order by 1;", 2541 Expected: []sql.Row{{1, 1}, {2, 2}}, 2542 }, 2543 }, 2544 }, 2545 { 2546 Name: "dolt_checkout with new branch forcefully", 2547 SetUpScript: []string{ 2548 "create table t (s varchar(5) primary key);", 2549 "insert into t values ('foo');", 2550 "call dolt_commit('-Am', 'commit main~2');", // will be main~2 2551 "insert into t values ('bar');", 2552 "call dolt_commit('-Am', 'commit main~1');", // will be main~1 2553 "insert into t values ('baz');", 2554 "call dolt_commit('-Am', 'commit main');", // will be main~1 2555 "call dolt_branch('testbr', 'main~1');", 2556 }, 2557 Assertions: []queries.ScriptTestAssertion{ 2558 { 2559 Query: "call dolt_checkout('-B', 'testbr', 'main~2');", 2560 SkipResultsCheck: true, 2561 }, 2562 { 2563 Query: "select active_branch();", 2564 Expected: []sql.Row{{"testbr"}}, 2565 }, 2566 { 2567 Query: "select * from t order by s;", 2568 Expected: []sql.Row{{"foo"}}, 2569 }, 2570 { 2571 Query: "call dolt_checkout('main');", 2572 SkipResultsCheck: true, 2573 }, 2574 { 2575 Query: "select active_branch();", 2576 Expected: []sql.Row{{"main"}}, 2577 }, 2578 { 2579 Query: "select * from t order by s;", 2580 Expected: []sql.Row{{"bar"}, {"baz"}, {"foo"}}, 2581 }, 2582 { 2583 Query: "call dolt_checkout('-B', 'testbr', 'main~1');", 2584 SkipResultsCheck: true, 2585 }, 2586 { 2587 Query: "select active_branch();", 2588 Expected: []sql.Row{{"testbr"}}, 2589 }, 2590 { 2591 Query: "select * from t order by s;", 2592 Expected: []sql.Row{{"bar"}, {"foo"}}, 2593 }, 2594 }, 2595 }, 2596 { 2597 Name: "dolt_checkout with new branch forcefully with dirty working set", 2598 SetUpScript: []string{ 2599 "create table t (s varchar(5) primary key);", 2600 "insert into t values ('foo');", 2601 "call dolt_commit('-Am', 'commit main~2');", // will be main~2 2602 "insert into t values ('bar');", 2603 "call dolt_commit('-Am', 'commit main~1');", // will be main~1 2604 "insert into t values ('baz');", 2605 "call dolt_commit('-Am', 'commit main');", // will be main~1 2606 "call dolt_checkout('-b', 'testbr', 'main~1');", 2607 "insert into t values ('qux');", 2608 }, 2609 Assertions: []queries.ScriptTestAssertion{ 2610 { 2611 Query: "select active_branch();", 2612 Expected: []sql.Row{{"testbr"}}, 2613 }, 2614 { 2615 Query: "select * from t order by s;", 2616 Expected: []sql.Row{{"bar"}, {"foo"}, {"qux"}}, // Dirty working set 2617 }, 2618 { 2619 Query: "call dolt_checkout('main');", 2620 SkipResultsCheck: true, 2621 }, 2622 { 2623 Query: "select * from t order by s;", 2624 Expected: []sql.Row{{"bar"}, {"baz"}, {"foo"}}, 2625 }, 2626 { 2627 Query: "call dolt_checkout('-B', 'testbr', 'main~1');", 2628 SkipResultsCheck: true, 2629 }, 2630 { 2631 Query: "select active_branch();", 2632 Expected: []sql.Row{{"testbr"}}, 2633 }, 2634 { 2635 Query: "select * from t order by s;", 2636 Expected: []sql.Row{{"bar"}, {"foo"}}, // Dirty working set was forcefully overwritten 2637 }, 2638 }, 2639 }, 2640 { 2641 Name: "dolt_checkout mixed with USE statements", 2642 SetUpScript: []string{ 2643 "create table t (a int primary key, b int);", 2644 "call dolt_commit('-Am', 'creating table t');", 2645 "call dolt_branch('b2');", 2646 "call dolt_branch('b3');", 2647 "insert into t values (1, 1);", 2648 "call dolt_commit('-Am', 'added values on main');", 2649 "call dolt_checkout('b2');", 2650 "insert into t values (2, 2);", 2651 "call dolt_commit('-am', 'added values on b2');", 2652 "call dolt_checkout('b3');", 2653 "insert into t values (3, 3);", 2654 "call dolt_commit('-am', 'added values on b3');", 2655 "call dolt_checkout('main');", 2656 }, 2657 Assertions: []queries.ScriptTestAssertion{ 2658 { 2659 Query: "select active_branch();", 2660 Expected: []sql.Row{{"main"}}, 2661 }, 2662 { 2663 Query: "select * from t;", 2664 Expected: []sql.Row{{1, 1}}, 2665 }, 2666 { 2667 Query: "use `mydb/b2`;", 2668 SkipResultsCheck: true, 2669 }, 2670 { 2671 Query: "select active_branch();", 2672 Expected: []sql.Row{{"b2"}}, 2673 }, 2674 { 2675 Query: "select * from t;", 2676 Expected: []sql.Row{{2, 2}}, 2677 }, 2678 { 2679 Query: "use `mydb/b3`;", 2680 SkipResultsCheck: true, 2681 }, 2682 { 2683 Query: "select active_branch();", 2684 Expected: []sql.Row{{"b3"}}, 2685 }, 2686 { 2687 Query: "select * from t;", 2688 Expected: []sql.Row{{3, 3}}, 2689 }, 2690 { 2691 Query: "use `mydb/main`", 2692 SkipResultsCheck: true, 2693 }, 2694 { 2695 Query: "select active_branch();", 2696 Expected: []sql.Row{{"main"}}, 2697 }, 2698 { 2699 Query: "select * from t;", 2700 Expected: []sql.Row{{1, 1}}, 2701 }, 2702 { 2703 Query: "use `mydb`", 2704 SkipResultsCheck: true, 2705 }, 2706 { 2707 Query: "select active_branch();", 2708 Expected: []sql.Row{{"main"}}, 2709 }, 2710 { 2711 Query: "select * from t;", 2712 Expected: []sql.Row{{1, 1}}, 2713 }, 2714 { 2715 Query: "call dolt_checkout('b2');", 2716 SkipResultsCheck: true, 2717 }, 2718 { 2719 Query: "use `mydb/b3`", 2720 SkipResultsCheck: true, 2721 }, 2722 { 2723 Query: "select active_branch();", 2724 Expected: []sql.Row{{"b3"}}, 2725 }, 2726 // Since b2 was the last branch checked out with dolt_checkout, it's what mydb resolves to 2727 { 2728 Query: "use `mydb`", 2729 SkipResultsCheck: true, 2730 }, 2731 { 2732 Query: "select active_branch();", 2733 Expected: []sql.Row{{"b2"}}, 2734 }, 2735 { 2736 Query: "select * from t;", 2737 Expected: []sql.Row{{2, 2}}, 2738 }, 2739 }, 2740 }, 2741 { 2742 Name: "dolt_checkout and base name resolution", 2743 SetUpScript: []string{ 2744 "create table t (a int primary key, b int);", 2745 "call dolt_commit('-Am', 'creating table t');", 2746 "call dolt_branch('b2');", 2747 "call dolt_branch('b3');", 2748 "insert into t values (1, 1);", 2749 "call dolt_commit('-Am', 'added values on main');", 2750 "call dolt_checkout('b2');", 2751 "insert into t values (2, 2);", 2752 "call dolt_commit('-am', 'added values on b2');", 2753 "call dolt_checkout('b3');", 2754 "insert into t values (3, 3);", 2755 "call dolt_commit('-am', 'added values on b3');", 2756 "call dolt_checkout('main');", 2757 }, 2758 Assertions: []queries.ScriptTestAssertion{ 2759 { 2760 Query: "select active_branch();", 2761 Expected: []sql.Row{{"main"}}, 2762 }, 2763 { 2764 Query: "select * from t;", 2765 Expected: []sql.Row{{1, 1}}, 2766 }, 2767 { 2768 Query: "use `mydb/b2`;", 2769 SkipResultsCheck: true, 2770 }, 2771 { 2772 Query: "select active_branch();", 2773 Expected: []sql.Row{{"b2"}}, 2774 }, 2775 { 2776 Query: "select * from t;", 2777 Expected: []sql.Row{{2, 2}}, 2778 }, 2779 { 2780 Query: "select * from mydb.t;", 2781 Expected: []sql.Row{{1, 1}}, 2782 }, 2783 { 2784 Query: "use `mydb/b3`;", 2785 SkipResultsCheck: true, 2786 }, 2787 { 2788 Query: "select active_branch();", 2789 Expected: []sql.Row{{"b3"}}, 2790 }, 2791 { 2792 Query: "select * from t;", 2793 Expected: []sql.Row{{3, 3}}, 2794 }, 2795 { 2796 Query: "select * from mydb.t;", 2797 Expected: []sql.Row{{1, 1}}, 2798 }, 2799 { 2800 Query: "select * from `mydb/b2`.t;", 2801 Expected: []sql.Row{{2, 2}}, 2802 }, 2803 { 2804 Query: "use `mydb/main`", 2805 SkipResultsCheck: true, 2806 }, 2807 { 2808 Query: "select active_branch();", 2809 Expected: []sql.Row{{"main"}}, 2810 }, 2811 { 2812 Query: "select * from t;", 2813 Expected: []sql.Row{{1, 1}}, 2814 }, 2815 { 2816 Query: "select * from mydb.t;", 2817 Expected: []sql.Row{{1, 1}}, 2818 }, 2819 { 2820 Query: "select * from `mydb/b3`.t;", 2821 Expected: []sql.Row{{3, 3}}, 2822 }, 2823 { 2824 Query: "use `mydb`", 2825 SkipResultsCheck: true, 2826 }, 2827 { 2828 Query: "select active_branch();", 2829 Expected: []sql.Row{{"main"}}, 2830 }, 2831 { 2832 Query: "select * from t;", 2833 Expected: []sql.Row{{1, 1}}, 2834 }, 2835 { 2836 Query: "select * from `mydb/main`.t;", 2837 Expected: []sql.Row{{1, 1}}, 2838 }, 2839 { 2840 Query: "call dolt_checkout('b2');", 2841 SkipResultsCheck: true, 2842 }, 2843 { 2844 Query: "use `mydb/b3`", 2845 SkipResultsCheck: true, 2846 }, 2847 { 2848 Query: "select active_branch();", 2849 Expected: []sql.Row{{"b3"}}, 2850 }, 2851 // Since b2 was the last branch checked out with dolt_checkout, it's what mydb resolves to 2852 { 2853 Query: "select * from `mydb`.t;", 2854 Expected: []sql.Row{{2, 2}}, 2855 }, 2856 { 2857 Query: "use `mydb`", 2858 SkipResultsCheck: true, 2859 }, 2860 { 2861 Query: "select active_branch();", 2862 Expected: []sql.Row{{"b2"}}, 2863 }, 2864 { 2865 Query: "select * from t;", 2866 Expected: []sql.Row{{2, 2}}, 2867 }, 2868 }, 2869 }, 2870 { 2871 Name: "dolt_checkout and base name resolution for commit", 2872 SetUpScript: []string{ 2873 "create table t (a int primary key, b int);", 2874 "call dolt_commit('-Am', 'creating table t');", 2875 "call dolt_branch('b2');", 2876 "call dolt_branch('b3');", 2877 "insert into t values (1, 1);", 2878 "call dolt_commit('-Am', 'added values on main');", 2879 "call dolt_checkout('b2');", 2880 "insert into t values (2, 2);", 2881 "call dolt_commit('-am', 'added values on b2');", 2882 "call dolt_checkout('b3');", 2883 "insert into t values (3, 3);", 2884 "call dolt_commit('-am', 'added values on b3');", 2885 "call dolt_checkout('b2');", 2886 }, 2887 Assertions: []queries.ScriptTestAssertion{ 2888 { 2889 Query: "call dolt_checkout('b2');", 2890 SkipResultsCheck: true, 2891 }, 2892 { 2893 Query: "select active_branch();", 2894 Expected: []sql.Row{{"b2"}}, 2895 }, 2896 2897 { 2898 Query: "use `mydb/main`", 2899 SkipResultsCheck: true, 2900 }, 2901 { 2902 Query: "select active_branch();", 2903 Expected: []sql.Row{{"main"}}, 2904 }, 2905 { 2906 Query: "insert into t values (4, 4);", 2907 Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, 2908 }, 2909 { 2910 Query: "select * from t order by 1;", 2911 Expected: []sql.Row{{1, 1}, {4, 4}}, 2912 }, 2913 { 2914 Query: "select * from `mydb/main`.t order by 1;", 2915 Expected: []sql.Row{{1, 1}, {4, 4}}, 2916 }, 2917 { 2918 Query: "select * from `mydb/b2`.t order by 1;", 2919 Expected: []sql.Row{{2, 2}}, 2920 }, 2921 }, 2922 }, 2923 { 2924 Name: "branch last checked out is deleted", 2925 SetUpScript: []string{ 2926 "create table t (a int primary key, b int);", 2927 "call dolt_commit('-Am', 'creating table t');", 2928 "call dolt_branch('b2');", 2929 "call dolt_branch('b3');", 2930 "insert into t values (1, 1);", 2931 "call dolt_commit('-Am', 'added values on main');", 2932 "call dolt_checkout('b2');", 2933 "insert into t values (2, 2);", 2934 "call dolt_commit('-am', 'added values on b2');", 2935 "call dolt_checkout('b3');", 2936 "insert into t values (3, 3);", 2937 "call dolt_commit('-am', 'added values on b3');", 2938 "call dolt_checkout('b2');", 2939 "use mydb/main", 2940 "call dolt_branch('-df', 'b2');", 2941 }, 2942 Assertions: []queries.ScriptTestAssertion{ 2943 { 2944 Query: "select active_branch();", 2945 Expected: []sql.Row{{"main"}}, 2946 }, 2947 { 2948 Query: "insert into t values (4, 4);", 2949 Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, 2950 }, 2951 { 2952 Query: "select * from t order by 1;", 2953 Expected: []sql.Row{{1, 1}, {4, 4}}, 2954 }, 2955 { 2956 Query: "select * from `mydb/main`.t order by 1;", 2957 Expected: []sql.Row{{1, 1}, {4, 4}}, 2958 }, 2959 { 2960 Query: "select * from `mydb/b2`.t order by 1;", 2961 ExpectedErrStr: "database not found: mydb/b2", 2962 }, 2963 }, 2964 }, 2965 { 2966 Name: "Using non-existent refs", 2967 SetUpScript: []string{ 2968 "create table t (a int primary key, b int);", 2969 "insert into t values (1, 1);", 2970 "call dolt_commit('-Am', 'creating table t');", 2971 "call dolt_branch('b1');", 2972 "call dolt_tag('tag1');", 2973 }, 2974 Assertions: []queries.ScriptTestAssertion{ 2975 { 2976 Query: "use mydb/b1", 2977 Expected: []sql.Row{}, 2978 }, 2979 { 2980 Query: "use mydb/b2", 2981 ExpectedErrStr: "database not found: mydb/b2", 2982 }, 2983 { 2984 Query: "use mydb/tag1", 2985 Expected: []sql.Row{}, 2986 }, 2987 { 2988 Query: "use mydb/tag2", 2989 ExpectedErrStr: "database not found: mydb/tag2", 2990 }, 2991 { 2992 Query: "use mydb/h4jks5lomp9u41r6902knn0pfr7lsgth", 2993 ExpectedErrStr: "database not found: mydb/h4jks5lomp9u41r6902knn0pfr7lsgth", 2994 }, 2995 { 2996 Query: "select * from `mydb/b2`.t;", 2997 ExpectedErrStr: "database not found: mydb/b2", 2998 }, 2999 { 3000 Query: "select * from `mydb/tag2`.t", 3001 ExpectedErrStr: "database not found: mydb/tag2", 3002 }, 3003 { 3004 Query: "select * from `mydb/h4jks5lomp9u41r6902knn0pfr7lsgth`.t", 3005 ExpectedErrStr: "database not found: mydb/h4jks5lomp9u41r6902knn0pfr7lsgth", 3006 }, 3007 }, 3008 }, 3009 } 3010 3011 var DoltCheckoutReadOnlyScripts = []queries.ScriptTest{ 3012 { 3013 Name: "dolt checkout -b returns an error for read-only databases", 3014 Assertions: []queries.ScriptTestAssertion{ 3015 { 3016 Query: "call dolt_checkout('-b', 'newBranch');", 3017 ExpectedErrStr: "unable to create new branch in a read-only database", 3018 }, 3019 }, 3020 }, 3021 { 3022 Name: "dolt checkout -B returns an error for read-only databases", 3023 Assertions: []queries.ScriptTestAssertion{ 3024 { 3025 Query: "call dolt_checkout('-B', 'newBranch');", 3026 ExpectedErrStr: "unable to create new branch in a read-only database", 3027 }, 3028 }, 3029 }, 3030 } 3031 3032 var DoltInfoSchemaScripts = []queries.ScriptTest{ 3033 { 3034 Name: "info_schema changes with dolt_checkout", 3035 SetUpScript: []string{ 3036 "create table t (a int primary key, b int);", 3037 "call dolt_commit('-Am', 'creating table t');", 3038 "call dolt_branch('b2');", 3039 "call dolt_branch('b3');", 3040 "call dolt_checkout('b2');", 3041 "alter table t add column c int;", 3042 "call dolt_commit('-am', 'added column c on branch b2');", 3043 "call dolt_checkout('b3');", 3044 "alter table t add column d int;", 3045 "call dolt_commit('-am', 'added column d on branch b3');", 3046 "call dolt_checkout('main');", 3047 }, 3048 Assertions: []queries.ScriptTestAssertion{ 3049 { 3050 Query: "select active_branch();", 3051 Expected: []sql.Row{{"main"}}, 3052 }, 3053 { 3054 Query: "select column_name from information_schema.columns where table_schema = 'mydb' and table_name = 't' order by 1;", 3055 Expected: []sql.Row{{"a"}, {"b"}}, 3056 }, 3057 { 3058 Query: "call dolt_checkout('b2');", 3059 SkipResultsCheck: true, 3060 }, 3061 { 3062 Query: "select active_branch();", 3063 Expected: []sql.Row{{"b2"}}, 3064 }, 3065 { 3066 Query: "select column_name from information_schema.columns where table_schema = 'mydb' and table_name = 't' order by 1;", 3067 Expected: []sql.Row{{"a"}, {"b"}, {"c"}}, 3068 }, 3069 { 3070 Query: "call dolt_checkout('b3');", 3071 SkipResultsCheck: true, 3072 }, 3073 { 3074 Query: "select active_branch();", 3075 Expected: []sql.Row{{"b3"}}, 3076 }, 3077 { 3078 Query: "select column_name from information_schema.columns where table_schema = 'mydb' and table_name = 't' order by 1;", 3079 Expected: []sql.Row{{"a"}, {"b"}, {"d"}}, 3080 }, 3081 }, 3082 }, 3083 { 3084 Name: "info_schema does not change with USE", 3085 SetUpScript: []string{ 3086 "create table t (a int primary key, b int);", 3087 "call dolt_commit('-Am', 'creating table t');", 3088 "call dolt_branch('b2');", 3089 "call dolt_branch('b3');", 3090 "alter table `mydb/b2`.t add column c int;", 3091 "alter table `mydb/b3`.t add column d int;", 3092 "use mydb/main;", 3093 }, 3094 Assertions: []queries.ScriptTestAssertion{ 3095 { 3096 Query: "select active_branch();", 3097 Expected: []sql.Row{{"main"}}, 3098 }, 3099 { 3100 Query: "/* main */ select column_name from information_schema.columns where table_schema = 'mydb' and table_name = 't' order by 1;", 3101 Expected: []sql.Row{{"a"}, {"b"}}, 3102 }, 3103 { 3104 Query: "use mydb/b2;", 3105 SkipResultsCheck: true, 3106 }, 3107 { 3108 Query: "select active_branch();", 3109 Expected: []sql.Row{{"b2"}}, 3110 }, 3111 { 3112 Query: "/* b2 */ select column_name from information_schema.columns where table_schema = 'mydb' and table_name = 't' order by 1;", 3113 Expected: []sql.Row{{"a"}, {"b"}}, 3114 }, 3115 { 3116 Query: "select column_name from information_schema.columns where table_schema = 'mydb/b2' and table_name = 't' order by 1;", 3117 Expected: []sql.Row{{"a"}, {"b"}, {"c"}}, 3118 }, 3119 { 3120 Query: "use mydb/b3;", 3121 SkipResultsCheck: true, 3122 }, 3123 { 3124 Query: "select active_branch();", 3125 Expected: []sql.Row{{"b3"}}, 3126 }, 3127 { 3128 Query: "/* b3 */ select column_name from information_schema.columns where table_schema = 'mydb' and table_name = 't' order by 1;", 3129 Expected: []sql.Row{{"a"}, {"b"}}, 3130 }, 3131 { 3132 Query: "select column_name from information_schema.columns where table_schema = 'mydb/b3' and table_name = 't' order by 1;", 3133 Expected: []sql.Row{{"a"}, {"b"}, {"d"}}, 3134 }, 3135 }, 3136 }, 3137 { 3138 Name: "info_schema when checked out branch was deleted", 3139 SetUpScript: []string{ 3140 "create table t (a int primary key, b int);", 3141 "call dolt_commit('-Am', 'creating table t');", 3142 "call dolt_branch('b2');", 3143 "alter table `mydb/b2`.t add column c int;", 3144 "call dolt_branch('b3');", 3145 "call dolt_checkout('b3')", 3146 "use mydb/main;", 3147 "call dolt_branch('-df', 'b3')", 3148 }, 3149 Assertions: []queries.ScriptTestAssertion{ 3150 { 3151 Query: "select active_branch();", 3152 Expected: []sql.Row{{"main"}}, 3153 }, 3154 { 3155 Query: "/* main */ select column_name from information_schema.columns where table_schema = 'mydb' and table_name = 't' order by 1;", 3156 Expected: []sql.Row{{"a"}, {"b"}}, 3157 }, 3158 { 3159 Query: "use mydb/b2;", 3160 SkipResultsCheck: true, 3161 }, 3162 { 3163 Query: "select active_branch();", 3164 Expected: []sql.Row{{"b2"}}, 3165 }, 3166 { 3167 Query: "/* b2 */ select column_name from information_schema.columns where table_schema = 'mydb' and table_name = 't' order by 1;", 3168 Expected: []sql.Row{{"a"}, {"b"}}, 3169 }, 3170 { 3171 Query: "select column_name from information_schema.columns where table_schema = 'mydb/b2' and table_name = 't' order by 1;", 3172 Expected: []sql.Row{{"a"}, {"b"}, {"c"}}, 3173 }, 3174 { 3175 Query: "select count(*) from information_schema.columns where table_schema = 'mydb/b3' and table_name = 't' order by 1;", 3176 Expected: []sql.Row{{0}}, 3177 }, 3178 }, 3179 }, 3180 } 3181 3182 var DoltBranchScripts = []queries.ScriptTest{ 3183 { 3184 Name: "Create branches from HEAD with dolt_branch procedure", 3185 Assertions: []queries.ScriptTestAssertion{ 3186 { 3187 Query: "CALL DOLT_BRANCH('myNewBranch1')", 3188 Expected: []sql.Row{{0}}, 3189 }, 3190 { 3191 Query: "SELECT COUNT(*) FROM DOLT_BRANCHES WHERE NAME='myNewBranch1';", 3192 Expected: []sql.Row{{1}}, 3193 }, 3194 { 3195 // Trying to recreate that branch fails without the force flag 3196 Query: "CALL DOLT_BRANCH('myNewBranch1')", 3197 ExpectedErrStr: "fatal: A branch named 'myNewBranch1' already exists.", 3198 }, 3199 { 3200 Query: "CALL DOLT_BRANCH('-f', 'myNewBranch1')", 3201 Expected: []sql.Row{{0}}, 3202 }, 3203 }, 3204 }, 3205 { 3206 Name: "Create branches from HEAD fails when using a non-branch revision", 3207 SetUpScript: []string{ 3208 "use `mydb/main~`", 3209 }, 3210 Assertions: []queries.ScriptTestAssertion{ 3211 { 3212 Query: "CALL DOLT_BRANCH('myNewBranch1')", 3213 ExpectedErrStr: "fatal: Unexpected error creating branch 'myNewBranch1' : this operation is not supported while in a detached head state", 3214 }, 3215 }, 3216 }, 3217 { 3218 Name: "Rename branches with dolt_branch procedure", 3219 Assertions: []queries.ScriptTestAssertion{ 3220 { 3221 Query: "CALL DOLT_BRANCH('myNewBranch1')", 3222 Expected: []sql.Row{{0}}, 3223 }, 3224 { 3225 Query: "CALL DOLT_BRANCH('myNewBranch2')", 3226 Expected: []sql.Row{{0}}, 3227 }, 3228 { 3229 // Renaming to an existing name fails without the force flag 3230 Query: "CALL DOLT_BRANCH('-m', 'myNewBranch1', 'myNewBranch2')", 3231 ExpectedErrStr: "already exists", 3232 }, 3233 { 3234 Query: "CALL DOLT_BRANCH('-mf', 'myNewBranch1', 'myNewBranch2')", 3235 Expected: []sql.Row{{0}}, 3236 }, 3237 { 3238 Query: "CALL DOLT_BRANCH('-m', 'myNewBranch2', 'myNewBranch3')", 3239 Expected: []sql.Row{{0}}, 3240 }, 3241 { 3242 Query: "CALL DOLT_BRANCH('-m', 'myNewBranch3', 'HEAD')", 3243 ExpectedErrStr: "not a valid user branch name", 3244 }, 3245 }, 3246 }, 3247 { 3248 Name: "Copy branches from other branches using dolt_branch procedure", 3249 SetUpScript: []string{ 3250 "CALL DOLT_BRANCH('myNewBranch1')", 3251 }, 3252 Assertions: []queries.ScriptTestAssertion{ 3253 { 3254 Query: "CALL DOLT_BRANCH('-c')", 3255 ExpectedErrStr: "error: invalid usage", 3256 }, 3257 { 3258 Query: "CALL DOLT_BRANCH('-c', 'myNewBranch1')", 3259 ExpectedErrStr: "error: invalid usage", 3260 }, 3261 { 3262 Query: "CALL DOLT_BRANCH('-c', 'myNewBranch2')", 3263 ExpectedErrStr: "error: invalid usage", 3264 }, 3265 { 3266 Query: "CALL DOLT_BRANCH('-c', '', '')", 3267 ExpectedErrStr: "error: cannot branch empty string", 3268 }, 3269 { 3270 Query: "CALL DOLT_BRANCH('-c', 'myNewBranch1', 'myNewBranch2')", 3271 Expected: []sql.Row{{0}}, 3272 }, 3273 { 3274 Query: "SELECT COUNT(*) FROM DOLT_BRANCHES WHERE NAME='myNewBranch2';", 3275 Expected: []sql.Row{{1}}, 3276 }, 3277 { 3278 Query: "CALL DOLT_BRANCH('-c', 'myNewBranch1', 'myNewBranch2')", 3279 ExpectedErrStr: "fatal: A branch named 'myNewBranch2' already exists.", 3280 }, 3281 { 3282 Query: "CALL DOLT_BRANCH('-cf', 'myNewBranch1', 'myNewBranch2')", 3283 Expected: []sql.Row{{0}}, 3284 }, 3285 { 3286 Query: "CALL DOLT_BRANCH('-c', 'myNewBranch1', 'HEAD')", 3287 ExpectedErrStr: "fatal: 'HEAD' is not a valid branch name.", 3288 }, 3289 }, 3290 }, 3291 { 3292 Name: "Delete branches with dolt_branch procedure", 3293 SetUpScript: []string{ 3294 "CALL DOLT_BRANCH('myNewBranch1')", 3295 "CALL DOLT_BRANCH('myNewBranch2')", 3296 "CALL DOLT_BRANCH('myNewBranch3')", 3297 "CALL DOLT_BRANCH('myNewBranchWithCommit')", 3298 "CALL DOLT_CHECKOUT('myNewBranchWithCommit')", 3299 "CALL DOLT_COMMIT('--allow-empty', '-am', 'empty commit')", 3300 "CALL DOLT_CHECKOUT('main')", 3301 }, 3302 Assertions: []queries.ScriptTestAssertion{ 3303 { 3304 Query: "CALL DOLT_BRANCH('-d')", 3305 ExpectedErrStr: "error: invalid usage", 3306 }, 3307 { 3308 Query: "CALL DOLT_BRANCH('-d', '')", 3309 ExpectedErrStr: "error: cannot branch empty string", 3310 }, 3311 { 3312 Query: "CALL DOLT_BRANCH('-d', 'branchDoesNotExist')", 3313 ExpectedErrStr: "branch not found", 3314 }, 3315 { 3316 Query: "CALL DOLT_BRANCH('-d', 'myNewBranch1')", 3317 Expected: []sql.Row{{0}}, 3318 }, 3319 { 3320 Query: "SELECT COUNT(*) FROM DOLT_BRANCHES WHERE NAME='myNewBranch1'", 3321 Expected: []sql.Row{{0}}, 3322 }, 3323 { 3324 Query: "CALL DOLT_BRANCH('-d', 'myNewBranch2', 'myNewBranch3')", 3325 Expected: []sql.Row{{0}}, 3326 }, 3327 { 3328 // Trying to delete a branch with unpushed changes fails without force option 3329 Query: "CALL DOLT_BRANCH('-d', 'myNewBranchWithCommit')", 3330 ExpectedErrStr: "branch 'myNewBranchWithCommit' is not fully merged", 3331 }, 3332 { 3333 Query: "CALL DOLT_BRANCH('-df', 'myNewBranchWithCommit')", 3334 Expected: []sql.Row{{0}}, 3335 }, 3336 }, 3337 }, 3338 { 3339 Name: "Create branch from startpoint", 3340 SetUpScript: []string{ 3341 "create table a (x int)", 3342 "call dolt_add('.')", 3343 "SET @commit1 = '';", 3344 "CALL DOLT_COMMIT_HASH_OUT(@commit1, '-am', 'add table a');", 3345 }, 3346 Assertions: []queries.ScriptTestAssertion{ 3347 { 3348 Query: "show tables", 3349 Expected: []sql.Row{{"a"}}, 3350 }, 3351 { 3352 Query: "CALL DOLT_CHECKOUT('-b', 'newBranch', 'head~1')", 3353 Expected: []sql.Row{{0, "Switched to branch 'newBranch'"}}, 3354 }, 3355 { 3356 Query: "show tables", 3357 Expected: []sql.Row{}, 3358 }, 3359 { 3360 Query: "CALL DOLT_CHECKOUT('-b', 'newBranch2', @commit1)", 3361 Expected: []sql.Row{{0, "Switched to branch 'newBranch2'"}}, 3362 }, 3363 { 3364 Query: "show tables", 3365 Expected: []sql.Row{{"a"}}, 3366 }, 3367 { 3368 Query: "CALL DOLT_CHECKOUT('-b', 'otherBranch', 'unknownCommit')", 3369 ExpectedErrStr: "fatal: 'unknownCommit' is not a commit and a branch 'otherBranch' cannot be created from it", 3370 }, 3371 }, 3372 }, 3373 { 3374 // https://github.com/dolthub/dolt/issues/6001 3375 Name: "-- allows escaping arg parsing to create/delete branch names that look like flags", 3376 Assertions: []queries.ScriptTestAssertion{ 3377 { 3378 Query: "select count(*) from dolt_branches where name='-b';", 3379 Expected: []sql.Row{{0}}, 3380 }, 3381 { 3382 Query: "call dolt_branch('--', '-b');", 3383 Expected: []sql.Row{{0}}, 3384 }, 3385 { 3386 Query: "select count(*) from dolt_branches where name='-b';", 3387 Expected: []sql.Row{{1}}, 3388 }, 3389 { 3390 Query: "call dolt_branch('-d', '-f', '--', '-b');", 3391 Expected: []sql.Row{{0}}, 3392 }, 3393 { 3394 Query: "select count(*) from dolt_branches where name='-b';", 3395 Expected: []sql.Row{{0}}, 3396 }, 3397 }, 3398 }, 3399 { 3400 Name: "Join same table at two commits", 3401 SetUpScript: []string{ 3402 "create table t (i int);", 3403 "insert into t values (1);", 3404 "call dolt_add('t');", 3405 "call dolt_commit('-m', 'add t');", 3406 "call dolt_branch('b1');", 3407 "insert into t values (2);", 3408 "call dolt_add('t');", 3409 "call dolt_commit('-m', 'insert into t');", 3410 }, 3411 Assertions: []queries.ScriptTestAssertion{ 3412 { 3413 Query: "select * from `mydb/b1`.t join t", 3414 Expected: []sql.Row{{1, 1}, {1, 2}}, 3415 }, 3416 { 3417 Query: "select * from `mydb/b1`.t join `mydb/main`.t", 3418 Expected: []sql.Row{{1, 1}, {1, 2}}, 3419 }, 3420 }, 3421 }, 3422 } 3423 3424 var DoltReset = []queries.ScriptTest{ 3425 { 3426 Name: "CALL DOLT_RESET('--hard') should reset the merge state after uncommitted merge", 3427 SetUpScript: []string{ 3428 "CREATE TABLE test1 (pk int NOT NULL, c1 int, c2 int, PRIMARY KEY (pk));", 3429 "CALL DOLT_ADD('.')", 3430 "INSERT INTO test1 values (0,1,1);", 3431 "CALL DOLT_COMMIT('-am', 'added table')", 3432 3433 "CALL DOLT_CHECKOUT('-b', 'merge_branch');", 3434 "UPDATE test1 set c1 = 2;", 3435 "CALL DOLT_COMMIT('-am', 'update pk 0 = 2,1 to test1');", 3436 3437 "CALL DOLT_CHECKOUT('main');", 3438 "UPDATE test1 set c2 = 2;", 3439 "CALL DOLT_COMMIT('-am', 'update pk 0 = 1,2 to test1');", 3440 3441 "CALL DOLT_MERGE('merge_branch');", 3442 3443 "CALL DOLT_RESET('--hard');", 3444 }, 3445 Assertions: []queries.ScriptTestAssertion{ 3446 { 3447 Query: "CALL DOLT_MERGE('--abort')", 3448 ExpectedErrStr: "fatal: There is no merge to abort", 3449 }, 3450 }, 3451 }, 3452 { 3453 Name: "CALL DOLT_RESET('--hard') should reset the merge state after conflicting merge", 3454 SetUpScript: []string{ 3455 "SET dolt_allow_commit_conflicts = on", 3456 "CREATE TABLE test1 (pk int NOT NULL, c1 int, c2 int, PRIMARY KEY (pk));", 3457 "CALL DOLT_ADD('.')", 3458 "INSERT INTO test1 values (0,1,1);", 3459 "CALL DOLT_COMMIT('-am', 'added table')", 3460 3461 "CALL DOLT_CHECKOUT('-b', 'merge_branch');", 3462 "UPDATE test1 set c1 = 2, c2 = 2;", 3463 "CALL DOLT_COMMIT('-am', 'update pk 0 = 2,2 to test1');", 3464 3465 "CALL DOLT_CHECKOUT('main');", 3466 "UPDATE test1 set c1 = 3, c2 = 3;", 3467 "CALL DOLT_COMMIT('-am', 'update pk 0 = 3,3 to test1');", 3468 3469 "CALL DOLT_MERGE('merge_branch');", 3470 "CALL DOLT_RESET('--hard');", 3471 }, 3472 Assertions: []queries.ScriptTestAssertion{ 3473 { 3474 Query: "CALL DOLT_MERGE('--abort')", 3475 ExpectedErrStr: "fatal: There is no merge to abort", 3476 }, 3477 }, 3478 }, 3479 } 3480 3481 func gcSetup() []string { 3482 queries := []string{ 3483 "create table t (pk int primary key);", 3484 "call dolt_commit('-Am', 'create table');", 3485 } 3486 for i := 0; i < 250; i++ { 3487 queries = append( 3488 queries, 3489 fmt.Sprintf("INSERT INTO t VALUES (%d);", i), 3490 fmt.Sprintf("CALL DOLT_COMMIT('-am', 'added pk %d')", i), 3491 ) 3492 } 3493 return queries 3494 } 3495 3496 var DoltGC = []queries.ScriptTest{ 3497 { 3498 Name: "base case: gc", 3499 SetUpScript: gcSetup(), 3500 Assertions: []queries.ScriptTestAssertion{ 3501 { 3502 Query: "CALL DOLT_GC(null);", 3503 ExpectedErrStr: "error: invalid usage", 3504 }, 3505 { 3506 Query: "CALL DOLT_GC('bad', '--shallow');", 3507 ExpectedErrStr: "error: invalid usage", 3508 }, 3509 { 3510 Query: "CALL DOLT_GC('--shallow');", 3511 Expected: []sql.Row{{1}}, 3512 }, 3513 { 3514 Query: "CALL DOLT_GC();", 3515 Expected: []sql.Row{{1}}, 3516 }, 3517 { 3518 Query: "CALL DOLT_GC();", 3519 ExpectedErrStr: "no changes since last gc", 3520 }, 3521 }, 3522 }, 3523 } 3524 3525 var LogTableFunctionScriptTests = []queries.ScriptTest{ 3526 { 3527 Name: "invalid arguments", 3528 SetUpScript: []string{ 3529 "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", 3530 "call dolt_add('.')", 3531 "set @Commit1 = '';", 3532 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", 3533 3534 "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", 3535 "set @Commit2 = '';", 3536 "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", 3537 }, 3538 Assertions: []queries.ScriptTestAssertion{ 3539 { 3540 Query: "SELECT * from dolt_log(null);", 3541 ExpectedErr: sql.ErrInvalidArgumentDetails, 3542 }, 3543 { 3544 Query: "SELECT * from dolt_log(null, null);", 3545 ExpectedErr: sql.ErrInvalidArgumentDetails, 3546 }, 3547 { 3548 Query: "SELECT * from dolt_log(null, '--not', null);", 3549 ExpectedErr: sql.ErrInvalidArgumentDetails, 3550 }, 3551 { 3552 Query: "SELECT * from dolt_log(@Commit1, '--not', null);", 3553 ExpectedErr: sql.ErrInvalidArgumentDetails, 3554 }, 3555 { 3556 Query: "SELECT * from dolt_log(@Commit1, '--min-parents', null);", 3557 ExpectedErr: sql.ErrInvalidArgumentDetails, 3558 }, 3559 { 3560 Query: "SELECT * from dolt_log(@Commit1, '--min-parents', 123);", 3561 ExpectedErr: sql.ErrInvalidArgumentDetails, 3562 }, 3563 { 3564 Query: "SELECT * from dolt_log(123, @Commit1);", 3565 ExpectedErr: sql.ErrInvalidArgumentDetails, 3566 }, 3567 { 3568 Query: "SELECT * from dolt_log(@Commit1, 123);", 3569 ExpectedErr: sql.ErrInvalidArgumentDetails, 3570 }, 3571 { 3572 Query: "SELECT * from dolt_log(@Commit1, '--not', 123);", 3573 ExpectedErr: sql.ErrInvalidArgumentDetails, 3574 }, 3575 { 3576 Query: "SELECT * from dolt_log('main..branch1', @Commit1);", 3577 ExpectedErr: sql.ErrInvalidArgumentDetails, 3578 }, 3579 { 3580 Query: "SELECT * from dolt_log('^main..branch1');", 3581 ExpectedErr: sql.ErrInvalidArgumentDetails, 3582 }, 3583 { 3584 Query: "SELECT * from dolt_log('^main...branch1');", 3585 ExpectedErr: sql.ErrInvalidArgumentDetails, 3586 }, 3587 { 3588 Query: "SELECT * from dolt_log(@Commit1, 'main..branch1');", 3589 ExpectedErr: sql.ErrInvalidArgumentDetails, 3590 }, 3591 { 3592 Query: "SELECT * from dolt_log(@Commit1, 'main...branch1');", 3593 ExpectedErr: sql.ErrInvalidArgumentDetails, 3594 }, 3595 { 3596 Query: "SELECT * from dolt_log('main..branch1', '--not', @Commit1);", 3597 ExpectedErr: sql.ErrInvalidArgumentDetails, 3598 }, 3599 { 3600 Query: "SELECT * from dolt_log('main...branch1', '--not', @Commit1);", 3601 ExpectedErr: sql.ErrInvalidArgumentDetails, 3602 }, 3603 { 3604 Query: "SELECT * from dolt_log('main', '--not', '^branch1');", 3605 ExpectedErr: sql.ErrInvalidArgumentDetails, 3606 }, 3607 { 3608 Query: "SELECT * from dolt_log('main', '--not', 'main..branch1');", 3609 ExpectedErr: sql.ErrInvalidArgumentDetails, 3610 }, 3611 { 3612 Query: "SELECT * from dolt_log('fake-branch');", 3613 ExpectedErrStr: "branch not found: fake-branch", 3614 }, 3615 { 3616 Query: "SELECT * from dolt_log('^fake-branch', 'main');", 3617 ExpectedErrStr: "branch not found: fake-branch", 3618 }, 3619 { 3620 Query: "SELECT * from dolt_log('fake-branch', '^main');", 3621 ExpectedErrStr: "branch not found: fake-branch", 3622 }, 3623 { 3624 Query: "SELECT * from dolt_log('main..fake-branch');", 3625 ExpectedErrStr: "branch not found: fake-branch", 3626 }, 3627 { 3628 Query: "SELECT * from dolt_log('main', '--not', 'fake-branch');", 3629 ExpectedErrStr: "branch not found: fake-branch", 3630 }, 3631 { 3632 Query: "SELECT * from dolt_log(concat('fake', '-', 'branch'));", 3633 ExpectedErr: sqle.ErrInvalidNonLiteralArgument, 3634 }, 3635 { 3636 Query: "SELECT * from dolt_log(hashof('main'));", 3637 ExpectedErr: sqle.ErrInvalidNonLiteralArgument, 3638 }, 3639 { 3640 Query: "SELECT * from dolt_log(@Commit3, '--not', hashof('main'));", 3641 ExpectedErr: sqle.ErrInvalidNonLiteralArgument, 3642 }, 3643 { 3644 Query: "SELECT * from dolt_log(@Commit1, LOWER(@Commit2));", 3645 ExpectedErr: sqle.ErrInvalidNonLiteralArgument, 3646 }, 3647 { 3648 Query: "SELECT parents from dolt_log();", 3649 ExpectedErrStr: `column "parents" could not be found in any table in scope`, 3650 }, 3651 { 3652 Query: "SELECT * from dolt_log('--decorate', 'invalid');", 3653 ExpectedErr: sql.ErrInvalidArgumentDetails, 3654 }, 3655 { 3656 Query: "SELECT * from dolt_log('--decorate', 123);", 3657 ExpectedErr: sql.ErrInvalidArgumentDetails, 3658 }, 3659 { 3660 Query: "SELECT * from dolt_log('--decorate', null);", 3661 ExpectedErr: sql.ErrInvalidArgumentDetails, 3662 }, 3663 { 3664 Query: "SELECT refs from dolt_log();", 3665 ExpectedErrStr: `column "refs" could not be found in any table in scope`, 3666 }, 3667 { 3668 Query: "SELECT refs from dolt_log('--decorate', 'auto');", 3669 ExpectedErrStr: `column "refs" could not be found in any table in scope`, 3670 }, 3671 { 3672 Query: "SELECT refs from dolt_log('--decorate', 'no');", 3673 ExpectedErrStr: `column "refs" could not be found in any table in scope`, 3674 }, 3675 }, 3676 }, 3677 { 3678 Name: "basic case with one revision", 3679 SetUpScript: []string{ 3680 "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", 3681 "call dolt_add('.')", 3682 "set @Commit1 = '';", 3683 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", 3684 3685 "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", 3686 "set @Commit2 = '';", 3687 "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", 3688 3689 "call dolt_checkout('-b', 'new-branch')", 3690 "insert into t values (3, 'three', 'four');", 3691 "set @Commit3 = '';", 3692 "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into t again');", 3693 "call dolt_checkout('main')", 3694 }, 3695 Assertions: []queries.ScriptTestAssertion{ 3696 { 3697 Query: "SELECT message from dolt_log();", 3698 Expected: []sql.Row{ 3699 {"inserting into t"}, 3700 {"creating table t"}, 3701 {"Initialize data repository"}, 3702 }, 3703 }, 3704 { 3705 Query: "SELECT message from dolt_log('main');", 3706 Expected: []sql.Row{ 3707 {"inserting into t"}, 3708 {"creating table t"}, 3709 {"Initialize data repository"}, 3710 }, 3711 }, 3712 { 3713 Query: "SELECT message from dolt_log(@Commit1);", 3714 Expected: []sql.Row{ 3715 {"creating table t"}, 3716 {"Initialize data repository"}, 3717 }, 3718 }, 3719 { 3720 Query: "SELECT message from dolt_log(@Commit2);", 3721 Expected: []sql.Row{ 3722 {"inserting into t"}, 3723 {"creating table t"}, 3724 {"Initialize data repository"}, 3725 }, 3726 }, 3727 { 3728 Query: "SELECT message from dolt_log(@Commit3);", 3729 Expected: []sql.Row{ 3730 {"inserting into t again"}, 3731 {"inserting into t"}, 3732 {"creating table t"}, 3733 {"Initialize data repository"}, 3734 }, 3735 }, 3736 { 3737 Query: "SELECT message from dolt_log('new-branch');", 3738 Expected: []sql.Row{ 3739 {"inserting into t again"}, 3740 {"inserting into t"}, 3741 {"creating table t"}, 3742 {"Initialize data repository"}, 3743 }, 3744 }, 3745 { 3746 Query: "SELECT message from dolt_log('main^');", 3747 Expected: []sql.Row{ 3748 {"creating table t"}, 3749 {"Initialize data repository"}, 3750 }, 3751 }, 3752 { 3753 Query: "SELECT message from dolt_log('main') join dolt_diff(@Commit1, @Commit2, 't') where commit_hash = to_commit;", 3754 Expected: []sql.Row{ 3755 {"inserting into t"}, 3756 {"inserting into t"}, 3757 }, 3758 }, 3759 }, 3760 }, 3761 { 3762 Name: "basic case with more than one revision or revision range", 3763 SetUpScript: []string{ 3764 "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", 3765 "call dolt_add('.');", 3766 "set @Commit1 = '';", 3767 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", 3768 3769 "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", 3770 "set @Commit2 = '';", 3771 "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t 2');", 3772 3773 "call dolt_checkout('-b', 'new-branch');", 3774 "insert into t values (3, 'three', 'four');", 3775 "set @Commit3 = '';", 3776 "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into t 3');", 3777 "insert into t values (4, 'four', 'five');", 3778 "set @Commit4 = '';", 3779 "call dolt_commit_hash_out(@Commit4, '-am', 'inserting into t 4');", 3780 3781 "call dolt_checkout('main');", 3782 "insert into t values (5, 'five', 'six');", 3783 "set @Commit5 = '';", 3784 "call dolt_commit_hash_out(@Commit5, '-am', 'inserting into t 5');", 3785 }, 3786 /* Commit graph: 3787 3 - 4 (new-branch) 3788 / 3789 0 - 1 - 2 - 5 (main) 3790 */ 3791 Assertions: []queries.ScriptTestAssertion{ 3792 { 3793 Query: "SELECT count(*) from dolt_log('^main', 'new-branch');", 3794 Expected: []sql.Row{{2}}, // 4, 3 3795 }, 3796 { 3797 Query: "SELECT count(*) from dolt_log('main..new-branch');", 3798 Expected: []sql.Row{{2}}, // 4, 3 3799 }, 3800 { 3801 Query: "SELECT count(*) from dolt_log('main...new-branch');", 3802 Expected: []sql.Row{{3}}, // 5, 4, 3 3803 }, 3804 { 3805 Query: "SELECT count(*) from dolt_log('new-branch', '--not', 'main');", 3806 Expected: []sql.Row{{2}}, // 4, 3 3807 }, 3808 { 3809 Query: "SELECT count(*) from dolt_log('new-branch', '^main');", 3810 Expected: []sql.Row{{2}}, // 4, 3 3811 }, 3812 { 3813 Query: "SELECT count(*) from dolt_log('^new-branch', 'main');", 3814 Expected: []sql.Row{{1}}, // 5 3815 }, 3816 { 3817 Query: "SELECT count(*) from dolt_log('main', '--not', 'new-branch');", 3818 Expected: []sql.Row{{1}}, // 5 3819 }, 3820 { 3821 Query: "SELECT count(*) from dolt_log('^main', 'main');", 3822 Expected: []sql.Row{{0}}, 3823 }, 3824 { 3825 Query: "SELECT count(*) from dolt_log('main..main');", 3826 Expected: []sql.Row{{0}}, 3827 }, 3828 { 3829 Query: "SELECT count(*) from dolt_log('main...main');", 3830 Expected: []sql.Row{{0}}, 3831 }, 3832 { 3833 Query: "SELECT count(*) from dolt_log('main', '--not', 'main');", 3834 Expected: []sql.Row{{0}}, 3835 }, 3836 { 3837 Query: "SELECT count(*) from dolt_log('^main~', 'main');", 3838 Expected: []sql.Row{{1}}, 3839 }, 3840 { 3841 Query: "SELECT count(*) from dolt_log('^main^', 'main');", 3842 Expected: []sql.Row{{1}}, // 5 3843 }, 3844 { 3845 Query: "SELECT count(*) from dolt_log('^main', 'main^');", 3846 Expected: []sql.Row{{0}}, 3847 }, 3848 { 3849 Query: "SELECT count(*) from dolt_log('^main', @Commit3);", 3850 Expected: []sql.Row{{1}}, 3851 }, 3852 { 3853 Query: "SELECT count(*) from dolt_log('^new-branch', @Commit5);", 3854 Expected: []sql.Row{{1}}, // 5 3855 }, 3856 { 3857 Query: "SELECT count(*) from dolt_log(@Commit3, '--not', @Commit2);", 3858 Expected: []sql.Row{{1}}, // 3 3859 }, 3860 { 3861 Query: "SELECT count(*) from dolt_log(@Commit4, '--not', @Commit2);", 3862 Expected: []sql.Row{{2}}, // 4, 3 3863 }, 3864 { 3865 Query: "SELECT count(*) from dolt_log('^main', '^new-branch');", 3866 Expected: []sql.Row{{0}}, 3867 }, 3868 { 3869 Query: "SELECT count(*) from dolt_log('^main', '--not', 'new-branch');", 3870 Expected: []sql.Row{{0}}, 3871 }, 3872 }, 3873 }, 3874 { 3875 Name: "basic case with one revision, row content", 3876 SetUpScript: []string{ 3877 "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", 3878 "call dolt_add('.')", 3879 "set @Commit1 = '';", 3880 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", 3881 3882 "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", 3883 "set @Commit2 = '';", 3884 "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", 3885 3886 "call dolt_checkout('-b', 'new-branch')", 3887 "insert into t values (3, 'three', 'four');", 3888 "set @Commit3 = '';", 3889 "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into t again', '--author', 'John Doe <johndoe@example.com>');", 3890 "call dolt_checkout('main')", 3891 }, 3892 Assertions: []queries.ScriptTestAssertion{ 3893 { 3894 Query: "SELECT commit_hash = @Commit2, commit_hash = @Commit1, committer, email, message from dolt_log();", 3895 Expected: []sql.Row{ 3896 {true, false, "root", "root@localhost", "inserting into t"}, 3897 {false, true, "root", "root@localhost", "creating table t"}, 3898 {false, false, "billy bob", "bigbillieb@fake.horse", "Initialize data repository"}, 3899 }, 3900 }, 3901 { 3902 Query: "SELECT commit_hash = @Commit2, committer, email, message from dolt_log('main') limit 1;", 3903 Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t"}}, 3904 }, 3905 { 3906 Query: "SELECT commit_hash = @Commit3, committer, email, message from dolt_log('new-branch') limit 1;", 3907 Expected: []sql.Row{{true, "John Doe", "johndoe@example.com", "inserting into t again"}}, 3908 }, 3909 { 3910 Query: "SELECT commit_hash = @Commit1, committer, email, message from dolt_log(@Commit1) limit 1;", 3911 Expected: []sql.Row{{true, "root", "root@localhost", "creating table t"}}, 3912 }, 3913 }, 3914 }, 3915 { 3916 Name: "basic case with more than one revision or revision range, row content", 3917 SetUpScript: []string{ 3918 "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", 3919 "call dolt_add('.');", 3920 "set @Commit1 = '';", 3921 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", 3922 3923 "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", 3924 "set @Commit2 = '';", 3925 "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t 2');", 3926 3927 "call dolt_checkout('-b', 'new-branch');", 3928 "insert into t values (3, 'three', 'four');", 3929 "set @Commit3 = '';", 3930 "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into t 3', '--author', 'John Doe <johndoe@example.com>');", 3931 "insert into t values (4, 'four', 'five');", 3932 "set @Commit4 = '';", 3933 "call dolt_commit_hash_out(@Commit4, '-am', 'inserting into t 4', '--author', 'John Doe <johndoe@example.com>');", 3934 3935 "call dolt_checkout('main');", 3936 "insert into t values (5, 'five', 'six');", 3937 "set @Commit5 = '';", 3938 "call dolt_commit_hash_out(@Commit5, '-am', 'inserting into t 5');", 3939 }, 3940 /* Commit graph: 3941 3 - 4 (new-branch) 3942 / 3943 0 - 1 - 2 - 5 (main) 3944 */ 3945 Assertions: []queries.ScriptTestAssertion{ 3946 { 3947 Query: "SELECT commit_hash = @Commit4, commit_hash = @Commit3, committer, email, message from dolt_log('^main', 'new-branch');", 3948 Expected: []sql.Row{ 3949 {true, false, "John Doe", "johndoe@example.com", "inserting into t 4"}, 3950 {false, true, "John Doe", "johndoe@example.com", "inserting into t 3"}, 3951 }, 3952 }, 3953 { 3954 Query: "SELECT commit_hash = @Commit4, commit_hash = @Commit3, committer, email, message from dolt_log('main..new-branch');", 3955 Expected: []sql.Row{ 3956 {true, false, "John Doe", "johndoe@example.com", "inserting into t 4"}, 3957 {false, true, "John Doe", "johndoe@example.com", "inserting into t 3"}, 3958 }, 3959 }, 3960 { 3961 Query: "SELECT commit_hash = @Commit5, commit_hash = @Commit4, commit_hash = @Commit3, committer, email, message from dolt_log('main...new-branch');", 3962 Expected: []sql.Row{ 3963 {true, false, false, "root", "root@localhost", "inserting into t 5"}, 3964 {false, true, false, "John Doe", "johndoe@example.com", "inserting into t 4"}, 3965 {false, false, true, "John Doe", "johndoe@example.com", "inserting into t 3"}, 3966 }, 3967 }, 3968 { 3969 Query: "SELECT commit_hash = @Commit4, commit_hash = @Commit3, committer, email, message from dolt_log('new-branch', '--not', 'main');", 3970 Expected: []sql.Row{ 3971 {true, false, "John Doe", "johndoe@example.com", "inserting into t 4"}, 3972 {false, true, "John Doe", "johndoe@example.com", "inserting into t 3"}, 3973 }, 3974 }, 3975 { 3976 Query: "SELECT commit_hash = @Commit4, commit_hash = @Commit3, committer, email, message from dolt_log('new-branch', '^main');", 3977 Expected: []sql.Row{ 3978 {true, false, "John Doe", "johndoe@example.com", "inserting into t 4"}, 3979 {false, true, "John Doe", "johndoe@example.com", "inserting into t 3"}, 3980 }, 3981 }, 3982 { 3983 Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log('^new-branch', 'main');", 3984 Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}}, 3985 }, 3986 { 3987 Query: "SELECT * from dolt_log('^main', 'main');", 3988 Expected: []sql.Row{}, 3989 }, 3990 { 3991 Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log('^main~', 'main');", 3992 Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}}, 3993 }, 3994 { 3995 Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log( 'main', '--not', 'main~');", 3996 Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}}, 3997 }, 3998 { 3999 Query: "SELECT commit_hash = @Commit3, committer, email, message from dolt_log('^main', @Commit3);", 4000 Expected: []sql.Row{{true, "John Doe", "johndoe@example.com", "inserting into t 3"}}, 4001 }, 4002 { 4003 Query: "SELECT commit_hash = @Commit3, committer, email, message from dolt_log(@Commit3, '--not', @Commit2);", 4004 Expected: []sql.Row{{true, "John Doe", "johndoe@example.com", "inserting into t 3"}}, 4005 }, 4006 { 4007 Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log('^new-branch', @Commit5);", 4008 Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}}, 4009 }, 4010 { 4011 Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log(@Commit5, '--not', @Commit4);", 4012 Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}}, 4013 }, 4014 }, 4015 }, 4016 { 4017 Name: "multiple revisions", 4018 SetUpScript: []string{ 4019 "create table t (pk int primary key);", 4020 "call dolt_add('.')", 4021 "call dolt_commit('-m', 'commit 1 MAIN [1M]')", 4022 "call dolt_commit('--allow-empty', '-m', 'commit 2 MAIN [2M]')", 4023 "call dolt_tag('tagM')", 4024 "call dolt_checkout('-b', 'branchA')", 4025 "call dolt_commit('--allow-empty', '-m', 'commit 1 BRANCHA [1A]')", 4026 "call dolt_commit('--allow-empty', '-m', 'commit 2 BRANCHA [2A]')", 4027 "call dolt_checkout('-b', 'branchB')", 4028 "call dolt_commit('--allow-empty', '-m', 'commit 1 BRANCHB [1B]')", 4029 "call dolt_checkout('branchA')", 4030 "call dolt_commit('--allow-empty', '-m', 'commit 3 BRANCHA [3A]')", 4031 "call dolt_checkout('main')", 4032 "call dolt_commit('--allow-empty', '-m', 'commit 3 AFTER [3M]')", 4033 }, 4034 /* 4035 4036 1B (branchB) 4037 / 4038 1A - 2A - 3A (branchA) 4039 / 4040 (init) - 1M - 2M - 3M (main) 4041 (tagM) 4042 4043 */ 4044 Assertions: []queries.ScriptTestAssertion{ 4045 { 4046 Query: "select message from dolt_log('branchB', 'branchA');", 4047 Expected: []sql.Row{ 4048 {"commit 3 BRANCHA [3A]"}, 4049 {"commit 1 BRANCHB [1B]"}, 4050 {"commit 2 BRANCHA [2A]"}, 4051 {"commit 1 BRANCHA [1A]"}, 4052 {"commit 2 MAIN [2M]"}, 4053 {"commit 1 MAIN [1M]"}, 4054 {"Initialize data repository"}, 4055 }, 4056 }, 4057 { 4058 Query: "select message from dolt_log('main', 'branchA');", 4059 Expected: []sql.Row{ 4060 {"commit 3 BRANCHA [3A]"}, 4061 {"commit 2 BRANCHA [2A]"}, 4062 {"commit 3 AFTER [3M]"}, 4063 {"commit 1 BRANCHA [1A]"}, 4064 {"commit 2 MAIN [2M]"}, 4065 {"commit 1 MAIN [1M]"}, 4066 {"Initialize data repository"}, 4067 }, 4068 }, 4069 { 4070 Query: "select message from dolt_log('main', 'branchB', 'branchA');", 4071 Expected: []sql.Row{ 4072 {"commit 3 BRANCHA [3A]"}, 4073 {"commit 1 BRANCHB [1B]"}, 4074 {"commit 2 BRANCHA [2A]"}, 4075 {"commit 3 AFTER [3M]"}, 4076 {"commit 1 BRANCHA [1A]"}, 4077 {"commit 2 MAIN [2M]"}, 4078 {"commit 1 MAIN [1M]"}, 4079 {"Initialize data repository"}, 4080 }, 4081 }, 4082 { 4083 Query: "select message from dolt_log('branchB', 'main', '^branchA');", 4084 Expected: []sql.Row{ 4085 {"commit 1 BRANCHB [1B]"}, 4086 {"commit 3 AFTER [3M]"}, 4087 }, 4088 }, 4089 { 4090 Query: "select message from dolt_log('branchB', 'main', '--not', 'branchA');", 4091 Expected: []sql.Row{ 4092 {"commit 1 BRANCHB [1B]"}, 4093 {"commit 3 AFTER [3M]"}, 4094 }, 4095 }, 4096 { 4097 Query: "select message from dolt_log('branchB', 'main', '^branchA', '^main');", 4098 Expected: []sql.Row{ 4099 {"commit 1 BRANCHB [1B]"}, 4100 }, 4101 }, 4102 { 4103 Query: "select message from dolt_log('tagM..branchB');", 4104 Expected: []sql.Row{ 4105 {"commit 1 BRANCHB [1B]"}, 4106 {"commit 2 BRANCHA [2A]"}, 4107 {"commit 1 BRANCHA [1A]"}, 4108 }, 4109 }, 4110 { 4111 Query: "select message from dolt_log('HEAD..branchB');", 4112 Expected: []sql.Row{ 4113 {"commit 1 BRANCHB [1B]"}, 4114 {"commit 2 BRANCHA [2A]"}, 4115 {"commit 1 BRANCHA [1A]"}, 4116 }, 4117 }, 4118 }, 4119 }, 4120 { 4121 Name: "table names given", 4122 SetUpScript: []string{ 4123 "create table test (pk int PRIMARY KEY)", 4124 "call dolt_add('.')", 4125 "call dolt_commit('-m', 'created table test [1M]')", 4126 "create table test2 (pk int PRIMARY KEY)", 4127 "call dolt_add('.')", 4128 "call dolt_commit('-m', 'created table test2 [2M]')", 4129 "call dolt_checkout('-b', 'test-branch')", 4130 "insert into test values (0)", 4131 "call dolt_add('.')", 4132 "call dolt_commit('-m', 'inserted 0 into test [1TB]')", 4133 "create table test3 (pk int PRIMARY KEY)", 4134 "call dolt_add('.')", 4135 "call dolt_commit('-m', 'created table test3 [2TB]')", 4136 "call dolt_checkout('main')", 4137 "insert into test values (1)", 4138 "call dolt_add('.')", 4139 "call dolt_commit('-m', 'inserted 1 into test [3M]')", 4140 "call dolt_merge('test-branch', '-m', 'merged test-branch [4M]')", 4141 "drop table test3", 4142 "call dolt_add('.')", 4143 "call dolt_commit('-m', 'dropped table test3 [5M]')", 4144 "insert into test values (2)", 4145 "call dolt_add('.')", 4146 "call dolt_commit('-m', 'inserted 2 into test [6M]')", 4147 }, 4148 /* 4149 4150 1TB - 2TB (test-branch) 4151 / \ 4152 (init) - 1M - 2M - 3M - 4M - 5M - 6M (main) 4153 4154 */ 4155 Assertions: []queries.ScriptTestAssertion{ 4156 { 4157 Query: "select message from dolt_log('--tables', 'test');", 4158 Expected: []sql.Row{ 4159 {"inserted 2 into test [6M]"}, 4160 {"merged test-branch [4M]"}, 4161 {"inserted 1 into test [3M]"}, 4162 {"inserted 0 into test [1TB]"}, 4163 {"created table test [1M]"}, 4164 }, 4165 }, 4166 { 4167 Query: "select message from dolt_log('--tables', 'test2');", 4168 Expected: []sql.Row{ 4169 {"created table test2 [2M]"}, 4170 }, 4171 }, 4172 { 4173 Query: "select message from dolt_log('--tables', 'test3')", 4174 Expected: []sql.Row{ 4175 {"dropped table test3 [5M]"}, 4176 {"created table test3 [2TB]"}, 4177 }, 4178 }, 4179 { 4180 Query: "select message from dolt_log('--tables', 'test,test2');", 4181 Expected: []sql.Row{ 4182 {"inserted 2 into test [6M]"}, 4183 {"merged test-branch [4M]"}, 4184 {"inserted 1 into test [3M]"}, 4185 {"inserted 0 into test [1TB]"}, 4186 {"created table test2 [2M]"}, 4187 {"created table test [1M]"}, 4188 }, 4189 }, 4190 { 4191 Query: "select message from dolt_log('test-branch', '--tables', 'test');", 4192 Expected: []sql.Row{ 4193 {"inserted 0 into test [1TB]"}, 4194 {"created table test [1M]"}, 4195 }, 4196 }, 4197 }, 4198 }, 4199 { 4200 Name: "min parents, merges, show parents, decorate", 4201 SetUpScript: []string{ 4202 "create table t (pk int primary key, c1 int);", 4203 "call dolt_add('.')", 4204 "set @Commit1 = '';", 4205 "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", 4206 4207 "call dolt_checkout('-b', 'branch1')", 4208 "insert into t values(0,0);", 4209 "set @Commit2 = '';", 4210 "call dolt_commit_hash_out(@Commit2, '-am', 'inserting 0,0');", 4211 4212 "call dolt_checkout('main')", 4213 "call dolt_checkout('-b', 'branch2')", 4214 "insert into t values(1,1);", 4215 "set @Commit3 = '';", 4216 "call dolt_commit_hash_out(@Commit3, '-am', 'inserting 1,1');", 4217 4218 "call dolt_checkout('main')", 4219 "call dolt_merge('branch1')", // fast-forward merge 4220 "call dolt_merge('branch2')", // actual merge with commit 4221 "call dolt_tag('v1')", 4222 }, 4223 Assertions: []queries.ScriptTestAssertion{ 4224 { 4225 Query: "SELECT committer, email, message from dolt_log('--merges');", 4226 Expected: []sql.Row{{"root", "root@localhost", "Merge branch 'branch2' into main"}}, 4227 }, 4228 { 4229 Query: "SELECT committer, email, message from dolt_log('--min-parents', '2');", 4230 Expected: []sql.Row{{"root", "root@localhost", "Merge branch 'branch2' into main"}}, 4231 }, 4232 { 4233 Query: "SELECT committer, email, message from dolt_log('main', '--min-parents', '2');", 4234 Expected: []sql.Row{{"root", "root@localhost", "Merge branch 'branch2' into main"}}, 4235 }, 4236 { 4237 Query: "SELECT count(*) from dolt_log('main');", 4238 Expected: []sql.Row{{5}}, 4239 }, 4240 { 4241 Query: "SELECT count(*) from dolt_log('main', '--min-parents', '1');", // Should show everything except first commit 4242 Expected: []sql.Row{{4}}, 4243 }, 4244 { 4245 Query: "SELECT count(*) from dolt_log('main', '--min-parents', '1', '--merges');", // --merges overrides --min-parents 4246 Expected: []sql.Row{{1}}, 4247 }, 4248 { 4249 Query: "SELECT committer, email, message from dolt_log('branch1..main', '--min-parents', '2');", 4250 Expected: []sql.Row{{"root", "root@localhost", "Merge branch 'branch2' into main"}}, 4251 }, 4252 { 4253 Query: "SELECT count(*) from dolt_log('--min-parents', '5');", 4254 Expected: []sql.Row{{0}}, 4255 }, 4256 { 4257 Query: "SELECT message, SUBSTRING_INDEX(parents, ', ', 1) = @Commit2, SUBSTRING_INDEX(parents, ', ', -1) = @Commit3 from dolt_log('main', '--parents', '--merges');", 4258 Expected: []sql.Row{{"Merge branch 'branch2' into main", true, true}}, // shows two parents for merge commit 4259 }, 4260 { 4261 Query: "SELECT commit_hash = @Commit3, parents = @Commit1 from dolt_log('branch2', '--parents') LIMIT 1;", // shows one parent for non-merge commit 4262 Expected: []sql.Row{{true, true}}, 4263 }, 4264 { 4265 Query: "SELECT message, SUBSTRING_INDEX(parents, ', ', 1) = @Commit2, SUBSTRING_INDEX(parents, ', ', -1) = @Commit3 from dolt_log('branch1..main', '--parents', '--merges') LIMIT 1;", 4266 Expected: []sql.Row{{"Merge branch 'branch2' into main", true, true}}, 4267 }, 4268 { 4269 Query: "SELECT commit_hash = @Commit2, parents = @Commit1 from dolt_log('branch2..branch1', '--parents') LIMIT 1;", 4270 Expected: []sql.Row{{true, true}}, 4271 }, 4272 { 4273 Query: "SELECT refs from dolt_log('--decorate', 'short') LIMIT 1;", 4274 Expected: []sql.Row{{"HEAD -> main, tag: v1"}}, 4275 }, 4276 { 4277 Query: "SELECT refs from dolt_log('--decorate', 'full') LIMIT 1;", 4278 Expected: []sql.Row{{"HEAD -> refs/heads/main, tag: refs/tags/v1"}}, 4279 }, 4280 { 4281 Query: "SELECT commit_hash = @Commit2, parents = @Commit1, refs from dolt_log('branch2..branch1', '--parents', '--decorate', 'short') LIMIT 1;", 4282 Expected: []sql.Row{{true, true, "HEAD -> branch1"}}, 4283 }, 4284 }, 4285 }, 4286 } 4287 4288 var LargeJsonObjectScriptTests = []queries.ScriptTest{ 4289 { 4290 Name: "JSON under max length limit", 4291 SetUpScript: []string{ 4292 "create table t (j JSON)", 4293 }, 4294 Assertions: []queries.ScriptTestAssertion{ 4295 { 4296 Query: `insert into t set j= concat('[', repeat('"word",', 10000000), '"word"]')`, 4297 Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, 4298 }, 4299 }, 4300 }, 4301 { 4302 Name: "JSON over max length limit", 4303 SetUpScript: []string{ 4304 "create table t (j JSON)", 4305 }, 4306 Assertions: []queries.ScriptTestAssertion{ 4307 { 4308 Query: `insert into t set j= concat('[', repeat('"word",', 50000000), '"word"]')`, 4309 ExpectedErr: types.ErrLengthTooLarge, 4310 }, 4311 }, 4312 }, 4313 } 4314 4315 var DoltTagTestScripts = []queries.ScriptTest{ 4316 { 4317 Name: "dolt-tag: SQL create tags", 4318 SetUpScript: []string{ 4319 "CREATE TABLE test(pk int primary key);", 4320 "CALL DOLT_ADD('.')", 4321 "INSERT INTO test VALUES (0),(1),(2);", 4322 "CALL DOLT_COMMIT('-am','created table test')", 4323 }, 4324 Assertions: []queries.ScriptTestAssertion{ 4325 { 4326 Query: "CALL DOLT_TAG('v1', 'HEAD')", 4327 Expected: []sql.Row{{0}}, 4328 }, 4329 { 4330 Query: "SELECT tag_name, IF(CHAR_LENGTH(tag_hash) < 0, NULL, 'not null'), tagger, email, IF(date IS NULL, NULL, 'not null'), message from dolt_tags", 4331 Expected: []sql.Row{{"v1", "not null", "billy bob", "bigbillieb@fake.horse", "not null", ""}}, 4332 }, 4333 { 4334 Query: "CALL DOLT_TAG('v2', '-m', 'create tag v2')", 4335 Expected: []sql.Row{{0}}, 4336 }, 4337 { 4338 Query: "SELECT tag_name, message from dolt_tags", 4339 Expected: []sql.Row{{"v1", ""}, {"v2", "create tag v2"}}, 4340 }, 4341 }, 4342 }, 4343 { 4344 Name: "dolt-tag: SQL delete tags", 4345 SetUpScript: []string{ 4346 "CREATE TABLE test(pk int primary key);", 4347 "CALL DOLT_ADD('.')", 4348 "INSERT INTO test VALUES (0),(1),(2);", 4349 "CALL DOLT_COMMIT('-am','created table test')", 4350 "CALL DOLT_TAG('v1', '-m', 'create tag v1')", 4351 "CALL DOLT_TAG('v2', '-m', 'create tag v2')", 4352 "CALL DOLT_TAG('v3', '-m', 'create tag v3')", 4353 }, 4354 Assertions: []queries.ScriptTestAssertion{ 4355 { 4356 Query: "SELECT tag_name, message from dolt_tags", 4357 Expected: []sql.Row{{"v1", "create tag v1"}, {"v2", "create tag v2"}, {"v3", "create tag v3"}}, 4358 }, 4359 { 4360 Query: "CALL DOLT_TAG('-d','v1')", 4361 Expected: []sql.Row{{0}}, 4362 }, 4363 { 4364 Query: "SELECT tag_name, message from dolt_tags", 4365 Expected: []sql.Row{{"v2", "create tag v2"}, {"v3", "create tag v3"}}, 4366 }, 4367 { 4368 Query: "CALL DOLT_TAG('-d','v2','v3')", 4369 Expected: []sql.Row{{0}}, 4370 }, 4371 { 4372 Query: "SELECT tag_name, message from dolt_tags", 4373 Expected: []sql.Row{}, 4374 }, 4375 }, 4376 }, 4377 { 4378 Name: "dolt-tag: SQL use a tag as a ref for merge", 4379 SetUpScript: []string{ 4380 "CREATE TABLE test(pk int primary key);", 4381 "CALL DOLT_ADD('.')", 4382 "INSERT INTO test VALUES (0),(1),(2);", 4383 "CALL DOLT_COMMIT('-am','created table test')", 4384 "DELETE FROM test WHERE pk = 0", 4385 "INSERT INTO test VALUES (3)", 4386 "CALL DOLT_COMMIT('-am','made changes')", 4387 }, 4388 Assertions: []queries.ScriptTestAssertion{ 4389 { 4390 Query: "CALL DOLT_TAG('v1','HEAD')", 4391 Expected: []sql.Row{{0}}, 4392 }, 4393 { 4394 Query: "CALL DOLT_CHECKOUT('-b','other','HEAD^')", 4395 Expected: []sql.Row{{0, "Switched to branch 'other'"}}, 4396 }, 4397 { 4398 Query: "INSERT INTO test VALUES (8), (9)", 4399 Expected: []sql.Row{{types.OkResult{RowsAffected: 2}}}, 4400 }, 4401 { 4402 Query: "CALL DOLT_COMMIT('-am','made changes in other')", 4403 Expected: []sql.Row{{doltCommit}}, 4404 }, 4405 { 4406 Query: "CALL DOLT_MERGE('v1')", 4407 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 4408 }, 4409 { 4410 Query: "SELECT * FROM test", 4411 Expected: []sql.Row{{1}, {2}, {3}, {8}, {9}}, 4412 }, 4413 }, 4414 }, 4415 } 4416 4417 var DoltRemoteTestScripts = []queries.ScriptTest{ 4418 { 4419 Name: "dolt-remote: SQL add remotes", 4420 Assertions: []queries.ScriptTestAssertion{ 4421 { 4422 Query: "CALL DOLT_REMOTE('add','origin','file://../test')", 4423 Expected: []sql.Row{{0}}, 4424 }, 4425 { 4426 Query: "SELECT name, IF(CHAR_LENGTH(url) < 0, NULL, 'not null'), fetch_specs, params FROM DOLT_REMOTES", 4427 Expected: []sql.Row{{"origin", "not null", types.MustJSON(`["refs/heads/*:refs/remotes/origin/*"]`), types.MustJSON(`{}`)}}, 4428 }, 4429 { 4430 Query: "CALL DOLT_REMOTE()", 4431 ExpectedErrStr: "error: invalid argument, use 'dolt_remotes' system table to list remotes", 4432 }, 4433 { 4434 Query: "CALL DOLT_REMOTE('origin')", 4435 ExpectedErrStr: "error: invalid argument", 4436 }, 4437 { 4438 Query: "INSERT INTO dolt_remotes (name, url) VALUES ('origin', 'file://../test')", 4439 ExpectedErrStr: "the dolt_remotes table is read-only; use the dolt_remote stored procedure to edit remotes", 4440 }, 4441 }, 4442 }, 4443 { 4444 Name: "dolt-remote: SQL remove remotes", 4445 SetUpScript: []string{ 4446 "CALL DOLT_REMOTE('add','origin1','file://.')", 4447 "CALL DOLT_REMOTE('add','origin2','aws://[dynamo_db_table:s3_bucket]/repo_name')", 4448 }, 4449 Assertions: []queries.ScriptTestAssertion{ 4450 { 4451 Query: "SELECT name, IF(CHAR_LENGTH(url) < 0, NULL, 'not null'), fetch_specs, params FROM DOLT_REMOTES", 4452 Expected: []sql.Row{ 4453 {"origin1", "not null", types.MustJSON(`["refs/heads/*:refs/remotes/origin1/*"]`), types.MustJSON(`{}`)}, 4454 {"origin2", "not null", types.MustJSON(`["refs/heads/*:refs/remotes/origin2/*"]`), types.MustJSON(`{}`)}}, 4455 }, 4456 { 4457 Query: "CALL DOLT_REMOTE('remove','origin2')", 4458 Expected: []sql.Row{{0}}, 4459 }, 4460 { 4461 Query: "SELECT name, IF(CHAR_LENGTH(url) < 0, NULL, 'not null'), fetch_specs, params FROM DOLT_REMOTES", 4462 Expected: []sql.Row{{"origin1", "not null", types.MustJSON(`["refs/heads/*:refs/remotes/origin1/*"]`), types.MustJSON(`{}`)}}, 4463 }, 4464 // 'origin1' remote must exist in order this error to be returned; otherwise, no error from EOF 4465 { 4466 Query: "DELETE FROM dolt_remotes WHERE name = 'origin1'", 4467 ExpectedErrStr: "the dolt_remotes table is read-only; use the dolt_remote stored procedure to edit remotes", 4468 }, 4469 }, 4470 }, 4471 { 4472 Name: "dolt-remote: multi-repo test", 4473 SetUpScript: []string{ 4474 "create database one", 4475 }, 4476 Assertions: []queries.ScriptTestAssertion{ 4477 { 4478 Query: "use one;", 4479 Expected: []sql.Row{}, 4480 }, 4481 { 4482 Query: "CALL DOLT_REMOTE('add','test01','file:///foo');", 4483 Expected: []sql.Row{{0}}, 4484 }, 4485 { 4486 Query: "select count(*) from dolt_remotes where name='test01';", 4487 Expected: []sql.Row{{1}}, 4488 }, 4489 { 4490 Query: "use mydb;", 4491 Expected: []sql.Row{}, 4492 }, 4493 { 4494 Query: "select count(*) from dolt_remotes where name='test01';", 4495 Expected: []sql.Row{{0}}, 4496 }, 4497 }, 4498 }, 4499 } 4500 4501 var DoltUndropTestScripts = []queries.ScriptTest{ 4502 { 4503 Name: "dolt-undrop", 4504 SetUpScript: []string{ 4505 "create database one;", 4506 "create database two;", 4507 "use one;", 4508 "create table t1(pk int primary key);", 4509 "insert into t1 values(1);", 4510 "call dolt_commit('-Am', 'creating table t1');", 4511 "use two;", 4512 "create table t2(pk int primary key);", 4513 "insert into t2 values(2);", 4514 "call dolt_commit('-Am', 'creating table t2');", 4515 }, 4516 Assertions: []queries.ScriptTestAssertion{ 4517 { 4518 Query: "show databases;", 4519 Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"one"}, {"two"}}, 4520 }, 4521 { 4522 Query: "drop database one;", 4523 Expected: []sql.Row{{types.NewOkResult(1)}}, 4524 }, 4525 { 4526 Query: "show databases;", 4527 Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"two"}}, 4528 }, 4529 { 4530 Query: "call dolt_undrop('one');", 4531 Expected: []sql.Row{{0}}, 4532 }, 4533 { 4534 Query: "show databases;", 4535 Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"one"}, {"two"}}, 4536 }, 4537 { 4538 Query: "use one;", 4539 Expected: []sql.Row{}, 4540 }, 4541 { 4542 Query: "select * from one.t1;", 4543 Expected: []sql.Row{{1}}, 4544 }, 4545 { 4546 Query: "select * from two.t2;", 4547 Expected: []sql.Row{{2}}, 4548 }, 4549 { 4550 Query: "drop database one;", 4551 Expected: []sql.Row{{types.NewOkResult(1)}}, 4552 }, 4553 { 4554 Query: "call dolt_undrop;", 4555 ExpectedErrStr: "no database name specified. available databases that can be undropped: one", 4556 }, 4557 { 4558 Query: "call dolt_purge_dropped_databases;", 4559 Expected: []sql.Row{{0}}, 4560 }, 4561 { 4562 Query: "show databases;", 4563 Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"two"}}, 4564 }, 4565 { 4566 Query: "call dolt_undrop;", 4567 ExpectedErrStr: "no database name specified. there are no databases currently available to be undropped", 4568 }, 4569 }, 4570 }, 4571 } 4572 4573 var DoltReflogTestScripts = []queries.ScriptTest{ 4574 { 4575 Name: "dolt_reflog: error cases", 4576 Assertions: []queries.ScriptTestAssertion{ 4577 { 4578 Query: "select * from dolt_reflog('foo', 'bar');", 4579 ExpectedErrStr: "error: dolt_reflog has too many positional arguments. Expected at most 1, found 2: ['foo' 'bar']", 4580 }, 4581 { 4582 Query: "select * from dolt_reflog(NULL);", 4583 ExpectedErrStr: "argument (<nil>) is not a string value, but a <nil>", 4584 }, 4585 { 4586 Query: "select * from dolt_reflog(-100);", 4587 ExpectedErrStr: "argument (-100) is not a string value, but a int8", 4588 }, 4589 }, 4590 }, 4591 { 4592 Name: "dolt_reflog: basic cases with no arguments", 4593 SetUpScript: []string{ 4594 "create table t1(pk int primary key);", 4595 "call dolt_commit('-Am', 'creating table t1');", 4596 4597 "insert into t1 values(1);", 4598 "call dolt_commit('-Am', 'inserting row 1');", 4599 "call dolt_tag('tag1');", 4600 4601 "call dolt_checkout('-b', 'branch1');", 4602 "insert into t1 values(2);", 4603 "call dolt_commit('-Am', 'inserting row 2');", 4604 4605 "insert into t1 values(3);", 4606 "call dolt_commit('-Am', 'inserting row 3');", 4607 "call dolt_tag('-d', 'tag1');", 4608 "call dolt_tag('tag1');", 4609 }, 4610 Assertions: []queries.ScriptTestAssertion{ 4611 { 4612 Query: "select ref, commit_hash, commit_message from dolt_reflog();", 4613 Expected: []sql.Row{ 4614 {"refs/tags/tag1", doltCommit, "inserting row 3"}, 4615 {"refs/heads/branch1", doltCommit, "inserting row 3"}, 4616 {"refs/heads/branch1", doltCommit, "inserting row 2"}, 4617 {"refs/heads/branch1", doltCommit, "inserting row 1"}, 4618 {"refs/tags/tag1", doltCommit, "inserting row 1"}, 4619 {"refs/heads/main", doltCommit, "inserting row 1"}, 4620 {"refs/heads/main", doltCommit, "creating table t1"}, 4621 {"refs/heads/main", doltCommit, "Initialize data repository"}, 4622 }, 4623 }, 4624 }, 4625 }, 4626 { 4627 Name: "dolt_reflog: basic cases with a ref argument", 4628 SetUpScript: []string{ 4629 "create table t1(pk int primary key);", 4630 "call dolt_commit('-Am', 'creating table t1');", 4631 4632 "insert into t1 values(1);", 4633 "call dolt_commit('-Am', 'inserting row 1');", 4634 "call dolt_tag('tag1');", 4635 4636 "call dolt_checkout('-b', 'branch1');", 4637 "insert into t1 values(2);", 4638 "call dolt_commit('-Am', 'inserting row 2');", 4639 4640 "insert into t1 values(3);", 4641 "call dolt_commit('-Am', 'inserting row 3');", 4642 "call dolt_tag('-d', 'tag1');", 4643 "call dolt_tag('tag1');", 4644 }, 4645 Assertions: []queries.ScriptTestAssertion{ 4646 { 4647 Query: "select * from dolt_reflog('doesNotExist');", 4648 Expected: []sql.Row{}, 4649 }, 4650 { 4651 Query: "select ref, commit_hash, commit_message from dolt_reflog('refs/heads/main')", 4652 Expected: []sql.Row{ 4653 {"refs/heads/main", doltCommit, "inserting row 1"}, 4654 {"refs/heads/main", doltCommit, "creating table t1"}, 4655 {"refs/heads/main", doltCommit, "Initialize data repository"}, 4656 }, 4657 }, { 4658 // ref is case-insensitive 4659 Query: "select ref, commit_hash, commit_message from dolt_reflog('reFS/Heads/MaIn')", 4660 Expected: []sql.Row{ 4661 {"refs/heads/main", doltCommit, "inserting row 1"}, 4662 {"refs/heads/main", doltCommit, "creating table t1"}, 4663 {"refs/heads/main", doltCommit, "Initialize data repository"}, 4664 }, 4665 }, { 4666 Query: "select ref, commit_hash, commit_message from dolt_reflog('main')", 4667 Expected: []sql.Row{ 4668 {"refs/heads/main", doltCommit, "inserting row 1"}, 4669 {"refs/heads/main", doltCommit, "creating table t1"}, 4670 {"refs/heads/main", doltCommit, "Initialize data repository"}, 4671 }, 4672 }, { 4673 // ref is case-insensitive 4674 Query: "select ref, commit_hash, commit_message from dolt_reflog('MaIN')", 4675 Expected: []sql.Row{ 4676 {"refs/heads/main", doltCommit, "inserting row 1"}, 4677 {"refs/heads/main", doltCommit, "creating table t1"}, 4678 {"refs/heads/main", doltCommit, "Initialize data repository"}, 4679 }, 4680 }, { 4681 Query: "select ref, commit_hash, commit_message from dolt_reflog('refs/heads/branch1')", 4682 Expected: []sql.Row{ 4683 {"refs/heads/branch1", doltCommit, "inserting row 3"}, 4684 {"refs/heads/branch1", doltCommit, "inserting row 2"}, 4685 {"refs/heads/branch1", doltCommit, "inserting row 1"}, 4686 }, 4687 }, { 4688 Query: "select ref, commit_hash, commit_message from dolt_reflog('branch1')", 4689 Expected: []sql.Row{ 4690 {"refs/heads/branch1", doltCommit, "inserting row 3"}, 4691 {"refs/heads/branch1", doltCommit, "inserting row 2"}, 4692 {"refs/heads/branch1", doltCommit, "inserting row 1"}, 4693 }, 4694 }, { 4695 Query: "select ref, commit_hash, commit_message from dolt_reflog('refs/tags/tag1')", 4696 Expected: []sql.Row{ 4697 {"refs/tags/tag1", doltCommit, "inserting row 3"}, 4698 {"refs/tags/tag1", doltCommit, "inserting row 1"}, 4699 }, 4700 }, { 4701 // ref is case-insensitive 4702 Query: "select ref, commit_hash, commit_message from dolt_reflog('Refs/TAGs/taG1')", 4703 Expected: []sql.Row{ 4704 {"refs/tags/tag1", doltCommit, "inserting row 3"}, 4705 {"refs/tags/tag1", doltCommit, "inserting row 1"}, 4706 }, 4707 }, { 4708 Query: "select ref, commit_hash, commit_message from dolt_reflog('tag1')", 4709 Expected: []sql.Row{ 4710 {"refs/tags/tag1", doltCommit, "inserting row 3"}, 4711 {"refs/tags/tag1", doltCommit, "inserting row 1"}, 4712 }, 4713 }, { 4714 // ref is case-insensitive 4715 Query: "select ref, commit_hash, commit_message from dolt_reflog('tAG1')", 4716 Expected: []sql.Row{ 4717 {"refs/tags/tag1", doltCommit, "inserting row 3"}, 4718 {"refs/tags/tag1", doltCommit, "inserting row 1"}, 4719 }, 4720 }, { 4721 // checkout main, so we can delete branch1 4722 Query: "call dolt_checkout('main');", 4723 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 4724 }, { 4725 // delete branch branch1 and make sure we can still query it in reflog 4726 Query: "call dolt_branch('-D', 'branch1')", 4727 Expected: []sql.Row{{0}}, 4728 }, { 4729 Query: "select ref, commit_hash, commit_message from dolt_reflog('branch1')", 4730 Expected: []sql.Row{ 4731 {"refs/heads/branch1", doltCommit, "inserting row 3"}, 4732 {"refs/heads/branch1", doltCommit, "inserting row 2"}, 4733 {"refs/heads/branch1", doltCommit, "inserting row 1"}, 4734 }, 4735 }, { 4736 // delete tag tag1 and make sure we can still query it in reflog 4737 Query: "call dolt_tag('-d', 'tag1')", 4738 Expected: []sql.Row{{0}}, 4739 }, { 4740 Query: "select ref, commit_hash, commit_message from dolt_reflog('tag1')", 4741 Expected: []sql.Row{ 4742 {"refs/tags/tag1", doltCommit, "inserting row 3"}, 4743 {"refs/tags/tag1", doltCommit, "inserting row 1"}, 4744 }, 4745 }, 4746 }, 4747 }, 4748 { 4749 Name: "dolt_reflog: garbage collection with no newgen data", 4750 Assertions: []queries.ScriptTestAssertion{ 4751 { 4752 Query: "select ref, commit_hash, commit_message from dolt_reflog('main')", 4753 Expected: []sql.Row{ 4754 {"refs/heads/main", doltCommit, "Initialize data repository"}, 4755 }, 4756 }, 4757 { 4758 Query: "call dolt_gc();", 4759 Expected: []sql.Row{{0}}, 4760 }, 4761 { 4762 // Calling dolt_gc() invalidates the session, so we have to ask this assertion to create a new session 4763 NewSession: true, 4764 Query: "select ref, commit_hash, commit_message from dolt_reflog('main')", 4765 Expected: []sql.Row{}, 4766 }, 4767 }, 4768 }, 4769 { 4770 Name: "dolt_reflog: garbage collection with newgen data", 4771 SetUpScript: []string{ 4772 "create table t1(pk int primary key);", 4773 "call dolt_commit('-Am', 'creating table t1');", 4774 "insert into t1 values(1);", 4775 "call dolt_commit('-Am', 'inserting row 1');", 4776 "call dolt_tag('tag1');", 4777 "insert into t1 values(2);", 4778 "call dolt_commit('-Am', 'inserting row 2');", 4779 }, 4780 Assertions: []queries.ScriptTestAssertion{ 4781 { 4782 Query: "select ref, commit_hash, commit_message from dolt_reflog('main')", 4783 Expected: []sql.Row{ 4784 {"refs/heads/main", doltCommit, "inserting row 2"}, 4785 {"refs/heads/main", doltCommit, "inserting row 1"}, 4786 {"refs/heads/main", doltCommit, "creating table t1"}, 4787 {"refs/heads/main", doltCommit, "Initialize data repository"}, 4788 }, 4789 }, 4790 { 4791 Query: "call dolt_gc();", 4792 Expected: []sql.Row{{0}}, 4793 }, 4794 { 4795 // Calling dolt_gc() invalidates the session, so we have to force this test to create a new session 4796 NewSession: true, 4797 Query: "select ref, commit_hash, commit_message from dolt_reflog('main')", 4798 Expected: []sql.Row{}, 4799 }, 4800 }, 4801 }, 4802 } 4803 4804 // DoltAutoIncrementTests is tests of dolt's global auto increment logic 4805 var DoltAutoIncrementTests = []queries.ScriptTest{ 4806 { 4807 Name: "insert on different branches", 4808 SetUpScript: []string{ 4809 "create table t (a int primary key auto_increment, b int)", 4810 "call dolt_add('.')", 4811 "call dolt_commit('-am', 'empty table')", 4812 "call dolt_branch('branch1')", 4813 "call dolt_branch('branch2')", 4814 }, 4815 Assertions: []queries.ScriptTestAssertion{ 4816 { 4817 Query: "insert into t (b) values (1), (2)", 4818 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 1}}}, 4819 }, 4820 { 4821 Query: "call dolt_commit('-am', 'two values on main')", 4822 Expected: []sql.Row{{doltCommit}}, 4823 }, 4824 { 4825 Query: "call dolt_checkout('branch1')", 4826 SkipResultsCheck: true, 4827 }, 4828 { 4829 Query: "insert into t (b) values (3), (4)", 4830 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 3}}}, 4831 }, 4832 { 4833 Query: "select * from t order by a", 4834 Expected: []sql.Row{ 4835 {3, 3}, 4836 {4, 4}, 4837 }, 4838 }, 4839 { 4840 Query: "call dolt_commit('-am', 'two values on branch1')", 4841 Expected: []sql.Row{{doltCommit}}, 4842 }, 4843 { 4844 Query: "call dolt_checkout('branch2')", 4845 SkipResultsCheck: true, 4846 }, 4847 { 4848 Query: "insert into t (b) values (5), (6)", 4849 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 5}}}, 4850 }, 4851 { 4852 Query: "select * from t order by a", 4853 Expected: []sql.Row{ 4854 {5, 5}, 4855 {6, 6}, 4856 }, 4857 }, 4858 }, 4859 }, 4860 { 4861 Name: "drop table", 4862 SetUpScript: []string{ 4863 "create table t (a int primary key auto_increment, b int)", 4864 "call dolt_add('.')", 4865 "call dolt_commit('-am', 'empty table')", 4866 "call dolt_branch('branch1')", 4867 "call dolt_branch('branch2')", 4868 "insert into t (b) values (1), (2)", 4869 "call dolt_commit('-am', 'two values on main')", 4870 "call dolt_checkout('branch1')", 4871 "insert into t (b) values (3), (4)", 4872 "call dolt_commit('-am', 'two values on branch1')", 4873 "call dolt_checkout('branch2')", 4874 "insert into t (b) values (5), (6)", 4875 "call dolt_checkout('branch1')", 4876 }, 4877 Assertions: []queries.ScriptTestAssertion{ 4878 { 4879 Query: "drop table t", 4880 Expected: []sql.Row{{types.NewOkResult(0)}}, 4881 }, 4882 { 4883 Query: "call dolt_checkout('main')", 4884 SkipResultsCheck: true, 4885 }, 4886 { 4887 // highest value in any branch is 6 4888 Query: "insert into t (b) values (7), (8)", 4889 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 7}}}, 4890 }, 4891 { 4892 Query: "select * from t order by a", 4893 Expected: []sql.Row{ 4894 {1, 1}, 4895 {2, 2}, 4896 {7, 7}, 4897 {8, 8}, 4898 }, 4899 }, 4900 { 4901 Query: "drop table t", 4902 Expected: []sql.Row{{types.NewOkResult(0)}}, 4903 }, 4904 { 4905 Query: "call dolt_checkout('branch2')", 4906 SkipResultsCheck: true, 4907 }, 4908 { 4909 // highest value in any branch is still 6 (dropped table above) 4910 Query: "insert into t (b) values (7), (8)", 4911 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 7}}}, 4912 }, 4913 { 4914 Query: "select * from t order by a", 4915 Expected: []sql.Row{ 4916 {5, 5}, 4917 {6, 6}, 4918 {7, 7}, 4919 {8, 8}, 4920 }, 4921 }, 4922 { 4923 Query: "drop table t", 4924 Expected: []sql.Row{{types.NewOkResult(0)}}, 4925 }, 4926 { 4927 Query: "create table t (a int primary key auto_increment, b int)", 4928 SkipResultsCheck: true, 4929 }, 4930 { 4931 // no value on any branch 4932 Query: "insert into t (b) values (1), (2)", 4933 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 1}}}, 4934 }, 4935 { 4936 Query: "select * from t order by a", 4937 Expected: []sql.Row{ 4938 {1, 1}, 4939 {2, 2}, 4940 }, 4941 }, 4942 }, 4943 }, 4944 { 4945 Name: "delete all rows in table", 4946 SetUpScript: []string{ 4947 "create table t (a int primary key auto_increment, b int)", 4948 "call dolt_add('.')", 4949 "call dolt_commit('-am', 'empty table')", 4950 "insert into t (b) values (1), (2)", 4951 "call dolt_commit('-am', 'two values on main')", 4952 }, 4953 Assertions: []queries.ScriptTestAssertion{ 4954 { 4955 Query: "delete from t", 4956 Expected: []sql.Row{{types.NewOkResult(2)}}, 4957 }, 4958 { 4959 Query: "alter table t auto_increment = 1", 4960 SkipResultsCheck: true, 4961 }, 4962 { 4963 // empty tables, start at 1 4964 Query: "insert into t (b) values (7), (8)", 4965 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 1}}}, 4966 }, 4967 { 4968 Query: "select * from t order by a", 4969 Expected: []sql.Row{ 4970 {1, 7}, 4971 {2, 8}, 4972 }, 4973 }, 4974 }, 4975 }, 4976 { 4977 Name: "set auto-increment below current max value", 4978 SetUpScript: []string{ 4979 "create table t (a int primary key auto_increment, b int)", 4980 "call dolt_add('.')", 4981 "call dolt_commit('-am', 'empty table')", 4982 "insert into t (b) values (1), (2), (3), (4)", 4983 "call dolt_commit('-am', 'two values on main')", 4984 }, 4985 Assertions: []queries.ScriptTestAssertion{ 4986 { 4987 Query: "alter table t auto_increment = 2", 4988 SkipResultsCheck: true, 4989 }, 4990 { 4991 // previous update was ignored 4992 Query: "insert into t (b) values (5), (6)", 4993 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 5}}}, 4994 }, 4995 { 4996 Query: "select * from t order by a", 4997 Expected: []sql.Row{ 4998 {1, 1}, 4999 {2, 2}, 5000 {3, 3}, 5001 {4, 4}, 5002 {5, 5}, 5003 {6, 6}, 5004 }, 5005 }, 5006 { 5007 Query: "insert into t (a, b) values (100, 100)", 5008 Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 100}}}, 5009 }, 5010 { 5011 Query: "alter table t auto_increment = 50", 5012 SkipResultsCheck: true, 5013 }, 5014 { 5015 // previous update was ignored, value still below max on that table 5016 Query: "insert into t (b) values (101)", 5017 Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 101}}}, 5018 }, 5019 { 5020 Query: "select * from t where a >= 100 order by a", 5021 Expected: []sql.Row{{100, 100}, {101, 101}}, 5022 }, 5023 }, 5024 }, 5025 { 5026 Name: "set auto-increment above current max value", 5027 SetUpScript: []string{ 5028 "create table t (a int primary key auto_increment, b int)", 5029 "call dolt_add('.')", 5030 "call dolt_commit('-am', 'empty table')", 5031 "insert into t (b) values (1), (2), (3), (4)", 5032 "call dolt_commit('-am', 'two values on main')", 5033 "call dolt_branch('branch1')", 5034 }, 5035 Assertions: []queries.ScriptTestAssertion{ 5036 { 5037 Query: "alter table t auto_increment = 20", 5038 SkipResultsCheck: true, 5039 }, 5040 { 5041 Query: "insert into `mydb/branch1`.t (b) values (5), (6)", 5042 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 20}}}, 5043 }, 5044 { 5045 Query: "insert into t (b) values (5), (6)", 5046 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 22}}}, 5047 }, 5048 { 5049 Query: "select * from t order by a", 5050 Expected: []sql.Row{ 5051 {1, 1}, 5052 {2, 2}, 5053 {3, 3}, 5054 {4, 4}, 5055 {22, 5}, 5056 {23, 6}, 5057 }, 5058 }, 5059 }, 5060 }, 5061 { 5062 Name: "delete all rows in table in all branches", 5063 SetUpScript: []string{ 5064 "create table t (a int primary key auto_increment, b int)", 5065 "call dolt_add('.')", 5066 "call dolt_commit('-am', 'empty table')", 5067 "call dolt_branch('branch1')", 5068 "call dolt_branch('branch2')", 5069 "insert into t (b) values (1), (2)", 5070 "call dolt_commit('-am', 'two values on main')", 5071 "call dolt_checkout('branch1')", 5072 "insert into t (b) values (3), (4)", 5073 "call dolt_commit('-am', 'two values on branch1')", 5074 "call dolt_checkout('branch2')", 5075 "insert into t (b) values (5), (6)", 5076 "call dolt_checkout('main')", 5077 }, 5078 Assertions: []queries.ScriptTestAssertion{ 5079 { 5080 Query: "delete from t", 5081 Expected: []sql.Row{{types.NewOkResult(2)}}, 5082 }, 5083 { 5084 Query: "delete from `mydb/branch1`.t", 5085 Expected: []sql.Row{{types.NewOkResult(2)}}, 5086 }, 5087 { 5088 Query: "delete from `mydb/branch2`.t", 5089 Expected: []sql.Row{{types.NewOkResult(2)}}, 5090 }, 5091 { 5092 Query: "alter table `mydb/branch1`.t auto_increment = 1", 5093 SkipResultsCheck: true, 5094 }, 5095 { 5096 Query: "alter table `mydb/branch2`.t auto_increment = 1", 5097 SkipResultsCheck: true, 5098 }, 5099 { 5100 Query: "alter table t auto_increment = 1", 5101 SkipResultsCheck: true, 5102 }, 5103 { 5104 // empty tables, start at 1 5105 Query: "insert into t (b) values (7), (8)", 5106 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 1}}}, 5107 }, 5108 { 5109 Query: "select * from t order by a", 5110 Expected: []sql.Row{ 5111 {1, 7}, 5112 {2, 8}, 5113 }, 5114 }, 5115 }, 5116 }, 5117 { 5118 Name: "delete all rows in table in all but one branch", 5119 SetUpScript: []string{ 5120 "create table t (a int primary key auto_increment, b int)", 5121 "call dolt_add('.')", 5122 "call dolt_commit('-am', 'empty table')", 5123 "call dolt_branch('branch1')", 5124 "call dolt_branch('branch2')", 5125 "insert into t (b) values (1), (2)", 5126 "call dolt_commit('-am', 'two values on main')", 5127 "call dolt_checkout('branch1')", 5128 "insert into t (b) values (3), (4)", 5129 "call dolt_commit('-am', 'two values on branch1')", 5130 "call dolt_checkout('branch2')", 5131 "insert into t (b) values (5), (6)", 5132 "call dolt_checkout('main')", 5133 }, 5134 Assertions: []queries.ScriptTestAssertion{ 5135 { 5136 Query: "delete from t", 5137 Expected: []sql.Row{{types.NewOkResult(2)}}, 5138 }, 5139 { 5140 Query: "delete from `mydb/branch1`.t", 5141 Expected: []sql.Row{{types.NewOkResult(2)}}, 5142 }, 5143 { 5144 Query: "delete from `mydb/branch2`.t", 5145 Expected: []sql.Row{{types.NewOkResult(2)}}, 5146 }, 5147 { 5148 Query: "alter table t auto_increment = 1", 5149 SkipResultsCheck: true, 5150 }, 5151 { 5152 Query: "alter table `mydb/branch2`.t auto_increment = 1", 5153 SkipResultsCheck: true, 5154 }, 5155 { 5156 // empty tables, start at 5 (highest remaining value, update above ignored) 5157 Query: "insert into t (b) values (5), (6)", 5158 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 5}}}, 5159 }, 5160 { 5161 Query: "select * from t order by a", 5162 Expected: []sql.Row{ 5163 {5, 5}, 5164 {6, 6}, 5165 }, 5166 }, 5167 }, 5168 }, 5169 { 5170 Name: "truncate table in all branches", 5171 SetUpScript: []string{ 5172 "create table t (a int primary key auto_increment, b int)", 5173 "call dolt_add('.')", 5174 "call dolt_commit('-am', 'empty table')", 5175 "call dolt_branch('branch1')", 5176 "call dolt_branch('branch2')", 5177 "insert into t (b) values (1), (2)", 5178 "call dolt_commit('-am', 'two values on main')", 5179 "call dolt_checkout('branch1')", 5180 "insert into t (b) values (3), (4)", 5181 "call dolt_commit('-am', 'two values on branch1')", 5182 "call dolt_checkout('branch2')", 5183 "insert into t (b) values (5), (6)", 5184 "call dolt_checkout('main')", 5185 }, 5186 Assertions: []queries.ScriptTestAssertion{ 5187 { 5188 Query: "truncate t", 5189 Expected: []sql.Row{{types.NewOkResult(2)}}, 5190 }, 5191 { 5192 Query: "truncate `mydb/branch1`.t", 5193 Expected: []sql.Row{{types.NewOkResult(2)}}, 5194 }, 5195 { 5196 Query: "truncate `mydb/branch2`.t", 5197 Expected: []sql.Row{{types.NewOkResult(2)}}, 5198 }, 5199 { 5200 Query: "alter table t auto_increment = 1", 5201 SkipResultsCheck: true, 5202 }, 5203 { 5204 // empty tables, start at 1 5205 Query: "insert into t (b) values (7), (8)", 5206 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 1}}}, 5207 }, 5208 { 5209 Query: "select * from t order by a", 5210 Expected: []sql.Row{ 5211 {1, 7}, 5212 {2, 8}, 5213 }, 5214 }, 5215 }, 5216 }, 5217 { 5218 Name: "truncate table", 5219 SetUpScript: []string{ 5220 "create table t (a int primary key auto_increment, b int)", 5221 "call dolt_add('.')", 5222 "call dolt_commit('-am', 'empty table')", 5223 "call dolt_branch('branch1')", 5224 "call dolt_branch('branch2')", 5225 "insert into t (b) values (1), (2)", 5226 "call dolt_commit('-am', 'two values on main')", 5227 "call dolt_checkout('branch1')", 5228 "insert into t (b) values (3), (4)", 5229 "call dolt_commit('-am', 'two values on branch1')", 5230 "call dolt_checkout('branch2')", 5231 "insert into t (b) values (5), (6)", 5232 "call dolt_checkout('branch1')", 5233 }, 5234 Assertions: []queries.ScriptTestAssertion{ 5235 { 5236 Query: "truncate table t", 5237 Expected: []sql.Row{{types.NewOkResult(2)}}, 5238 }, 5239 { 5240 Query: "call dolt_checkout('main')", 5241 SkipResultsCheck: true, 5242 }, 5243 { 5244 // highest value in any branch is 6 5245 Query: "insert into t (b) values (7), (8)", 5246 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 7}}}, 5247 }, 5248 { 5249 Query: "select * from t order by a", 5250 Expected: []sql.Row{ 5251 {1, 1}, 5252 {2, 2}, 5253 {7, 7}, 5254 {8, 8}, 5255 }, 5256 }, 5257 { 5258 Query: "truncate table t", 5259 Expected: []sql.Row{{types.NewOkResult(4)}}, 5260 }, 5261 { 5262 Query: "call dolt_checkout('branch2')", 5263 SkipResultsCheck: true, 5264 }, 5265 { 5266 // highest value in any branch is still 6 (truncated table above) 5267 Query: "insert into t (b) values (7), (8)", 5268 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 7}}}, 5269 }, 5270 { 5271 Query: "select * from t order by a", 5272 Expected: []sql.Row{ 5273 {5, 5}, 5274 {6, 6}, 5275 {7, 7}, 5276 {8, 8}, 5277 }, 5278 }, 5279 { 5280 Query: "truncate table t", 5281 Expected: []sql.Row{{types.NewOkResult(4)}}, 5282 }, 5283 { 5284 // no value on any branch 5285 Query: "insert into t (b) values (1), (2)", 5286 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 1}}}, 5287 }, 5288 { 5289 Query: "select * from t order by a", 5290 Expected: []sql.Row{ 5291 {1, 1}, 5292 {2, 2}, 5293 }, 5294 }, 5295 }, 5296 }, 5297 { 5298 // Dropping the primary key constraint from a table implicitly truncates the table, which resets the 5299 // auto_increment value for the table to 0. These tests assert that the correct auto_increment value is 5300 // restored after the drop pk operation. 5301 Name: "drop auto_increment primary key", 5302 SetUpScript: []string{ 5303 "create table t (a int primary key auto_increment, b int, key (a))", 5304 "call dolt_commit('-Am', 'empty table')", 5305 "call dolt_branch('branch1')", 5306 "call dolt_branch('branch2')", 5307 "insert into t (b) values (1), (2)", 5308 "call dolt_commit('-am', 'two values on main')", 5309 "call dolt_checkout('branch1')", 5310 "insert into t (b) values (3), (4)", 5311 "call dolt_commit('-am', 'two values on branch1')", 5312 "call dolt_checkout('branch2')", 5313 "insert into t (b) values (5), (6)", 5314 "call dolt_checkout('main')", 5315 }, 5316 Assertions: []queries.ScriptTestAssertion{ 5317 { 5318 Query: "alter table t drop primary key", 5319 Expected: []sql.Row{{types.NewOkResult(0)}}, 5320 }, 5321 { 5322 // highest value in any branch is 6 5323 Query: "insert into t (b) values (7), (8)", 5324 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 7}}}, 5325 }, 5326 { 5327 Query: "select * from t order by a", 5328 Expected: []sql.Row{ 5329 {1, 1}, 5330 {2, 2}, 5331 {7, 7}, 5332 {8, 8}, 5333 }, 5334 }, 5335 { 5336 Query: "call dolt_checkout('branch2')", 5337 SkipResultsCheck: true, 5338 }, 5339 { 5340 Query: "insert into t (b) values (9), (10)", 5341 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 9}}}, 5342 }, 5343 { 5344 Query: "select * from t order by a", 5345 Expected: []sql.Row{ 5346 {5, 5}, 5347 {6, 6}, 5348 {9, 9}, 5349 {10, 10}, 5350 }, 5351 }, 5352 { 5353 Query: "alter table t drop primary key", 5354 Expected: []sql.Row{{types.NewOkResult(0)}}, 5355 }, 5356 { 5357 Query: "insert into t (b) values (11), (12)", 5358 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 11}}}, 5359 }, 5360 { 5361 Query: "select * from t order by a", 5362 Expected: []sql.Row{ 5363 {5, 5}, 5364 {6, 6}, 5365 {9, 9}, 5366 {10, 10}, 5367 {11, 11}, 5368 {12, 12}, 5369 }, 5370 }, 5371 }, 5372 }, 5373 } 5374 5375 var DoltCherryPickTests = []queries.ScriptTest{ 5376 { 5377 Name: "error cases: basic validation", 5378 SetUpScript: []string{ 5379 "create table t (pk int primary key, v varchar(100));", 5380 "call dolt_commit('-Am', 'create table t');", 5381 "call dolt_checkout('-b', 'branch1');", 5382 "insert into t values (1, \"one\");", 5383 "call dolt_commit('-am', 'adding row 1');", 5384 "set @commit1 = hashof('HEAD');", 5385 "call dolt_checkout('main');", 5386 }, 5387 Assertions: []queries.ScriptTestAssertion{ 5388 { 5389 Query: "CALL Dolt_Cherry_Pick('HEAD~100');", 5390 ExpectedErrStr: "invalid ancestor spec", 5391 }, 5392 { 5393 Query: "CALL Dolt_Cherry_Pick('abcdaaaaaaaaaaaaaaaaaaaaaaaaaaaa');", 5394 ExpectedErrStr: "target commit not found", 5395 }, 5396 { 5397 Query: "CALL Dolt_Cherry_Pick('--abort');", 5398 ExpectedErrStr: "error: There is no cherry-pick merge to abort", 5399 }, 5400 }, 5401 }, 5402 { 5403 Name: "error cases: merge commits cannot be cherry-picked", 5404 SetUpScript: []string{ 5405 "create table t (pk int primary key, v varchar(100));", 5406 "call dolt_commit('-Am', 'create table t');", 5407 "call dolt_checkout('-b', 'branch1');", 5408 "insert into t values (1, \"one\");", 5409 "call dolt_commit('-am', 'adding row 1');", 5410 "set @commit1 = hashof('HEAD');", 5411 "call dolt_checkout('main');", 5412 }, 5413 Assertions: []queries.ScriptTestAssertion{ 5414 { 5415 Query: "CALL dolt_merge('--no-ff', 'branch1');", 5416 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 5417 }, 5418 { 5419 Query: "CALL dolt_cherry_pick('HEAD');", 5420 ExpectedErrStr: "cherry-picking a merge commit is not supported", 5421 }, 5422 }, 5423 }, 5424 { 5425 Name: "error cases: error with staged or unstaged changes ", 5426 SetUpScript: []string{ 5427 "create table t (pk int primary key, v varchar(100));", 5428 "call dolt_commit('-Am', 'create table t');", 5429 "call dolt_checkout('-b', 'branch1');", 5430 "insert into t values (1, \"one\");", 5431 "call dolt_commit('-am', 'adding row 1');", 5432 "set @commit1 = hashof('HEAD');", 5433 "call dolt_checkout('main');", 5434 "INSERT INTO t VALUES (100, 'onehundy');", 5435 }, 5436 Assertions: []queries.ScriptTestAssertion{ 5437 { 5438 Query: "CALL Dolt_Cherry_Pick(@commit1);", 5439 ExpectedErrStr: "cannot cherry-pick with uncommitted changes", 5440 }, 5441 { 5442 Query: "call dolt_add('t');", 5443 Expected: []sql.Row{{0}}, 5444 }, 5445 { 5446 Query: "CALL Dolt_Cherry_Pick(@commit1);", 5447 ExpectedErrStr: "cannot cherry-pick with uncommitted changes", 5448 }, 5449 }, 5450 }, 5451 { 5452 Name: "error cases: different primary keys", 5453 SetUpScript: []string{ 5454 "create table t (pk int primary key, v varchar(100));", 5455 "call dolt_commit('-Am', 'create table t');", 5456 "call dolt_checkout('-b', 'branch1');", 5457 "ALTER TABLE t DROP PRIMARY KEY, ADD PRIMARY KEY (pk, v);", 5458 "call dolt_commit('-am', 'adding row 1');", 5459 "set @commit1 = hashof('HEAD');", 5460 "call dolt_checkout('main');", 5461 }, 5462 Assertions: []queries.ScriptTestAssertion{ 5463 { 5464 Query: "CALL Dolt_Cherry_Pick(@commit1);", 5465 ExpectedErrStr: "error: cannot merge because table t has different primary keys", 5466 }, 5467 }, 5468 }, 5469 { 5470 Name: "basic case", 5471 SetUpScript: []string{ 5472 "create table t (pk int primary key, v varchar(100));", 5473 "call dolt_commit('-Am', 'create table t');", 5474 "call dolt_checkout('-b', 'branch1');", 5475 "insert into t values (1, \"one\");", 5476 "call dolt_commit('-am', 'adding row 1');", 5477 "set @commit1 = hashof('HEAD');", 5478 "insert into t values (2, \"two\");", 5479 "call dolt_commit('-am', 'adding row 2');", 5480 "set @commit2 = hashof('HEAD');", 5481 "call dolt_checkout('main');", 5482 }, 5483 Assertions: []queries.ScriptTestAssertion{ 5484 { 5485 Query: "SELECT * FROM t;", 5486 Expected: []sql.Row{}, 5487 }, 5488 { 5489 Query: "call dolt_cherry_pick(@commit2);", 5490 Expected: []sql.Row{{doltCommit, 0, 0, 0}}, 5491 }, 5492 { 5493 Query: "SELECT * FROM t;", 5494 Expected: []sql.Row{{2, "two"}}, 5495 }, 5496 { 5497 Query: "call dolt_cherry_pick(@commit1);", 5498 Expected: []sql.Row{{doltCommit, 0, 0, 0}}, 5499 }, 5500 { 5501 Query: "SELECT * FROM t order by pk;", 5502 Expected: []sql.Row{{1, "one"}, {2, "two"}}, 5503 }, 5504 { 5505 // Assert that our new commit only has one parent (i.e. not a merge commit) 5506 Query: "select count(*) from dolt_commit_ancestors where commit_hash = hashof('HEAD');", 5507 Expected: []sql.Row{{1}}, 5508 }, 5509 }, 5510 }, 5511 { 5512 Name: "keyless table", 5513 SetUpScript: []string{ 5514 "call dolt_checkout('main');", 5515 "CREATE TABLE keyless (id int, name varchar(10));", 5516 "call dolt_commit('-Am', 'create table keyless on main');", 5517 "call dolt_checkout('-b', 'branch1');", 5518 "INSERT INTO keyless VALUES (1,'1'), (2,'3');", 5519 "call dolt_commit('-am', 'insert rows into keyless table on branch1');", 5520 "call dolt_checkout('main');", 5521 }, 5522 Assertions: []queries.ScriptTestAssertion{ 5523 { 5524 Query: "SELECT * FROM keyless;", 5525 Expected: []sql.Row{}, 5526 }, 5527 { 5528 Query: "CALL DOLT_CHERRY_PICK('branch1');", 5529 Expected: []sql.Row{{doltCommit, 0, 0, 0}}, 5530 }, 5531 { 5532 Query: "SELECT * FROM keyless;", 5533 Expected: []sql.Row{{1, "1"}, {2, "3"}}, 5534 }, 5535 }, 5536 }, 5537 { 5538 Name: "schema change: CREATE TABLE", 5539 SetUpScript: []string{ 5540 "call dolt_checkout('-b', 'branch1');", 5541 "CREATE TABLE table_a (pk BIGINT PRIMARY KEY, v varchar(10));", 5542 "INSERT INTO table_a VALUES (11, 'aa'), (22, 'ab');", 5543 "call dolt_commit('-Am', 'create table table_a');", 5544 "set @commit1 = hashof('HEAD');", 5545 "call dolt_checkout('main');", 5546 }, 5547 Assertions: []queries.ScriptTestAssertion{ 5548 { 5549 Query: "SHOW TABLES;", 5550 Expected: []sql.Row{}, 5551 }, 5552 { 5553 Query: "call dolt_cherry_pick(@commit1);", 5554 Expected: []sql.Row{{doltCommit, 0, 0, 0}}, 5555 }, 5556 { 5557 // Assert that our new commit only has one parent (i.e. not a merge commit) 5558 Query: "select count(*) from dolt_commit_ancestors where commit_hash = hashof('HEAD');", 5559 Expected: []sql.Row{{1}}, 5560 }, 5561 { 5562 Query: "SHOW TABLES;", 5563 Expected: []sql.Row{{"table_a"}}, 5564 }, 5565 { 5566 Query: "SELECT * FROM table_a;", 5567 Expected: []sql.Row{{11, "aa"}, {22, "ab"}}, 5568 }, 5569 }, 5570 }, 5571 { 5572 Name: "schema change: DROP TABLE", 5573 SetUpScript: []string{ 5574 "CREATE TABLE dropme (pk BIGINT PRIMARY KEY, v varchar(10));", 5575 "INSERT INTO dropme VALUES (11, 'aa'), (22, 'ab');", 5576 "call dolt_commit('-Am', 'create table dropme');", 5577 "call dolt_checkout('-b', 'branch1');", 5578 "drop table dropme;", 5579 "call dolt_commit('-Am', 'drop table dropme');", 5580 "set @commit1 = hashof('HEAD');", 5581 "call dolt_checkout('main');", 5582 }, 5583 Assertions: []queries.ScriptTestAssertion{ 5584 { 5585 Query: "SHOW TABLES;", 5586 Expected: []sql.Row{{"dropme"}}, 5587 }, 5588 { 5589 Query: "call dolt_cherry_pick(@commit1);", 5590 Expected: []sql.Row{{doltCommit, 0, 0, 0}}, 5591 }, 5592 { 5593 Query: "SHOW TABLES;", 5594 Expected: []sql.Row{}, 5595 }, 5596 }, 5597 }, 5598 { 5599 Name: "schema change: ALTER TABLE ADD COLUMN", 5600 SetUpScript: []string{ 5601 "create table test(pk int primary key);", 5602 "call dolt_commit('-Am', 'create table test on main');", 5603 "call dolt_checkout('-b', 'branch1');", 5604 "ALTER TABLE test ADD COLUMN v VARCHAR(100);", 5605 "call dolt_commit('-am', 'add column v to test on branch1');", 5606 "set @commit1 = hashof('HEAD');", 5607 "call dolt_checkout('main');", 5608 }, 5609 Assertions: []queries.ScriptTestAssertion{ 5610 { 5611 Query: "call dolt_cherry_pick(@commit1);", 5612 Expected: []sql.Row{{doltCommit, 0, 0, 0}}, 5613 }, 5614 { 5615 Query: "SHOW CREATE TABLE test;", 5616 Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `pk` int NOT NULL,\n `v` varchar(100),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 5617 }, 5618 }, 5619 }, 5620 { 5621 Name: "schema change: ALTER TABLE DROP COLUMN", 5622 SetUpScript: []string{ 5623 "create table test(pk int primary key, v varchar(100));", 5624 "call dolt_commit('-Am', 'create table test on main');", 5625 "call dolt_checkout('-b', 'branch1');", 5626 "ALTER TABLE test DROP COLUMN v;", 5627 "call dolt_commit('-am', 'drop column v from test on branch1');", 5628 "set @commit1 = hashof('HEAD');", 5629 "call dolt_checkout('main');", 5630 }, 5631 Assertions: []queries.ScriptTestAssertion{ 5632 { 5633 Query: "call dolt_cherry_pick(@commit1);", 5634 Expected: []sql.Row{{doltCommit, 0, 0, 0}}, 5635 }, 5636 { 5637 Query: "SHOW CREATE TABLE test;", 5638 Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `pk` int NOT NULL,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 5639 }, 5640 }, 5641 }, 5642 { 5643 Name: "schema change: ALTER TABLE RENAME COLUMN", 5644 SetUpScript: []string{ 5645 "create table test(pk int primary key, v1 varchar(100));", 5646 "call dolt_commit('-Am', 'create table test on main');", 5647 "call dolt_checkout('-b', 'branch1');", 5648 "ALTER TABLE test RENAME COLUMN v1 to v2;", 5649 "call dolt_commit('-am', 'rename column v1 to v2 in test on branch1');", 5650 "set @commit1 = hashof('HEAD');", 5651 "call dolt_checkout('main');", 5652 }, 5653 Assertions: []queries.ScriptTestAssertion{ 5654 { 5655 Query: "call dolt_cherry_pick(@commit1);", 5656 Expected: []sql.Row{{doltCommit, 0, 0, 0}}, 5657 }, 5658 { 5659 Query: "SHOW CREATE TABLE test;", 5660 Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `pk` int NOT NULL,\n `v2` varchar(100),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 5661 }, 5662 }, 5663 }, 5664 { 5665 Name: "abort (@@autocommit=0)", 5666 SetUpScript: []string{ 5667 "SET @@autocommit=0;", 5668 "create table t (pk int primary key, v varchar(100));", 5669 "insert into t values (1, 'one');", 5670 "call dolt_commit('-Am', 'create table t');", 5671 "call dolt_checkout('-b', 'branch1');", 5672 "update t set v=\"uno\" where pk=1;", 5673 "call dolt_commit('-Am', 'updating row 1 -> uno');", 5674 "alter table t drop column v;", 5675 "call dolt_commit('-am', 'drop column v');", 5676 "call dolt_checkout('main');", 5677 }, 5678 Assertions: []queries.ScriptTestAssertion{ 5679 { 5680 Query: "call dolt_cherry_pick(hashof('branch1'));", 5681 Expected: []sql.Row{{"", 1, 0, 0}}, 5682 }, 5683 { 5684 Query: "select * from dolt_conflicts;", 5685 Expected: []sql.Row{{"t", uint64(1)}}, 5686 }, 5687 { 5688 Query: "select base_pk, base_v, our_pk, our_diff_type, their_pk, their_diff_type from dolt_conflicts_t;", 5689 Expected: []sql.Row{ 5690 {1, "uno", 1, "modified", 1, "modified"}, 5691 }, 5692 }, 5693 { 5694 Query: "call dolt_cherry_pick('--abort');", 5695 Expected: []sql.Row{{"", 0, 0, 0}}, 5696 }, 5697 { 5698 Query: "select * from dolt_conflicts;", 5699 Expected: []sql.Row{}, 5700 }, 5701 { 5702 Query: "select * from t;", 5703 Expected: []sql.Row{{1, "one"}}, 5704 }, 5705 }, 5706 }, 5707 { 5708 Name: "abort (@@autocommit=1)", 5709 SetUpScript: []string{ 5710 "SET @@autocommit=1;", 5711 "SET @@dolt_allow_commit_conflicts=1;", 5712 "create table t (pk int primary key, v varchar(100));", 5713 "insert into t values (1, 'one');", 5714 "call dolt_commit('-Am', 'create table t');", 5715 "call dolt_checkout('-b', 'branch1');", 5716 "update t set v=\"uno\" where pk=1;", 5717 "call dolt_commit('-Am', 'updating row 1 -> uno');", 5718 "alter table t drop column v;", 5719 "call dolt_commit('-am', 'drop column v');", 5720 "call dolt_checkout('main');", 5721 }, 5722 Assertions: []queries.ScriptTestAssertion{ 5723 { 5724 Query: "call dolt_cherry_pick(hashof('branch1'));", 5725 Expected: []sql.Row{{"", 1, 0, 0}}, 5726 }, 5727 { 5728 Query: "select * from dolt_conflicts;", 5729 Expected: []sql.Row{{"t", uint64(1)}}, 5730 }, 5731 { 5732 Query: "select base_pk, base_v, our_pk, our_diff_type, their_pk, their_diff_type from dolt_conflicts_t;", 5733 Expected: []sql.Row{ 5734 {1, "uno", 1, "modified", 1, "modified"}, 5735 }, 5736 }, 5737 { 5738 Query: "call dolt_cherry_pick('--abort');", 5739 Expected: []sql.Row{{"", 0, 0, 0}}, 5740 }, 5741 { 5742 Query: "select * from dolt_conflicts;", 5743 Expected: []sql.Row{}, 5744 }, 5745 { 5746 Query: "select * from t;", 5747 Expected: []sql.Row{{1, "one"}}, 5748 }, 5749 }, 5750 }, 5751 { 5752 Name: "conflict resolution (@@autocommit=0)", 5753 SetUpScript: []string{ 5754 "SET @@autocommit=0;", 5755 "create table t (pk int primary key, v varchar(100));", 5756 "insert into t values (1, 'one');", 5757 "call dolt_commit('-Am', 'create table t');", 5758 "call dolt_checkout('-b', 'branch1');", 5759 "update t set v=\"uno\" where pk=1;", 5760 "call dolt_commit('-Am', 'updating row 1 -> uno');", 5761 "alter table t drop column v;", 5762 "call dolt_commit('-am', 'drop column v');", 5763 "call dolt_checkout('main');", 5764 }, 5765 Assertions: []queries.ScriptTestAssertion{ 5766 { 5767 Query: "call dolt_cherry_pick(hashof('branch1'));", 5768 Expected: []sql.Row{{"", 1, 0, 0}}, 5769 }, 5770 { 5771 Query: "select * from dolt_conflicts;", 5772 Expected: []sql.Row{{"t", uint64(1)}}, 5773 }, 5774 { 5775 Query: "select * from dolt_status", 5776 Expected: []sql.Row{{"t", false, "modified"}, {"t", false, "conflict"}}, 5777 }, 5778 { 5779 Query: "select base_pk, base_v, our_pk, our_diff_type, their_pk, their_diff_type from dolt_conflicts_t;", 5780 Expected: []sql.Row{ 5781 {1, "uno", 1, "modified", 1, "modified"}, 5782 }, 5783 }, 5784 { 5785 Query: "call dolt_conflicts_resolve('--ours', 't');", 5786 Expected: []sql.Row{{0}}, 5787 }, 5788 { 5789 Query: "select * from dolt_status", 5790 Expected: []sql.Row{{"t", false, "modified"}}, 5791 }, 5792 { 5793 Query: "select * from dolt_conflicts;", 5794 Expected: []sql.Row{}, 5795 }, 5796 { 5797 Query: "select * from t;", 5798 Expected: []sql.Row{{1}}, 5799 }, 5800 { 5801 Query: "call dolt_commit('-am', 'committing cherry-pick');", 5802 Expected: []sql.Row{{doltCommit}}, 5803 }, 5804 { 5805 // Assert that our new commit only has one parent (i.e. not a merge commit) 5806 Query: "select count(*) from dolt_commit_ancestors where commit_hash = hashof('HEAD');", 5807 Expected: []sql.Row{{1}}, 5808 }, 5809 }, 5810 }, 5811 { 5812 Name: "conflict resolution (@@autocommit=1)", 5813 SetUpScript: []string{ 5814 "set @@autocommit=1;", 5815 "SET @@dolt_allow_commit_conflicts=1;", 5816 "create table t (pk int primary key, c1 varchar(100));", 5817 "call dolt_commit('-Am', 'creating table t');", 5818 "insert into t values (1, \"one\");", 5819 "call dolt_commit('-Am', 'inserting row 1');", 5820 "SET @commit1 = hashof('HEAD');", 5821 "update t set c1=\"uno\" where pk=1;", 5822 "call dolt_commit('-Am', 'updating row 1 -> uno');", 5823 "update t set c1=\"ein\" where pk=1;", 5824 "call dolt_commit('-Am', 'updating row 1 -> ein');", 5825 "SET @commit2 = hashof('HEAD');", 5826 "call dolt_reset('--hard', @commit1);", 5827 }, 5828 Assertions: []queries.ScriptTestAssertion{ 5829 { 5830 Query: "SELECT * from dolt_status;", 5831 Expected: []sql.Row{}, 5832 }, 5833 { 5834 Query: "SELECT * from t;", 5835 Expected: []sql.Row{{1, "one"}}, 5836 }, 5837 { 5838 Query: `CALL dolt_cherry_pick(@commit2);`, 5839 Expected: []sql.Row{{"", 1, 0, 0}}, 5840 }, 5841 { 5842 Query: `SELECT * FROM dolt_conflicts;`, 5843 Expected: []sql.Row{{"t", uint64(1)}}, 5844 }, 5845 { 5846 Query: `commit;`, 5847 Expected: []sql.Row{}, 5848 }, 5849 { 5850 Query: `SELECT * FROM dolt_conflicts;`, 5851 Expected: []sql.Row{{"t", uint64(1)}}, 5852 }, 5853 { 5854 Query: `SELECT base_pk, base_c1, our_pk, our_c1, their_diff_type, their_pk, their_c1 FROM dolt_conflicts_t;`, 5855 Expected: []sql.Row{{1, "uno", 1, "one", "modified", 1, "ein"}}, 5856 }, 5857 { 5858 Query: `SELECT * FROM t;`, 5859 Expected: []sql.Row{{1, "one"}}, 5860 }, 5861 { 5862 Query: `call dolt_conflicts_resolve('--theirs', 't');`, 5863 Expected: []sql.Row{{0}}, 5864 }, 5865 { 5866 Query: `SELECT * FROM t;`, 5867 Expected: []sql.Row{{1, "ein"}}, 5868 }, 5869 { 5870 Query: "call dolt_commit('-am', 'committing cherry-pick');", 5871 Expected: []sql.Row{{doltCommit}}, 5872 }, 5873 { 5874 // Assert that our new commit only has one parent (i.e. not a merge commit) 5875 Query: "select count(*) from dolt_commit_ancestors where commit_hash = hashof('HEAD');", 5876 Expected: []sql.Row{{1}}, 5877 }, 5878 }, 5879 }, 5880 { 5881 Name: "abort (@@autocommit=1) with ignored table", 5882 SetUpScript: []string{ 5883 "INSERT INTO dolt_ignore VALUES ('generated_*', 1);", 5884 "CREATE TABLE generated_foo (pk int PRIMARY KEY);", 5885 "CREATE TABLE generated_bar (pk int PRIMARY KEY);", 5886 "insert into generated_foo values (1);", 5887 "insert into generated_bar values (1);", 5888 "SET @@autocommit=1;", 5889 "SET @@dolt_allow_commit_conflicts=1;", 5890 "create table t (pk int primary key, v varchar(100));", 5891 "insert into t values (1, 'one');", 5892 "call dolt_add('--force', 'generated_bar');", 5893 "call dolt_commit('-Am', 'create table t');", 5894 "call dolt_checkout('-b', 'branch1');", 5895 "update t set v=\"uno\" where pk=1;", 5896 "call dolt_commit('-Am', 'updating row 1 -> uno');", 5897 "alter table t drop column v;", 5898 "call dolt_commit('-am', 'drop column v');", 5899 "call dolt_checkout('main');", 5900 }, 5901 Assertions: []queries.ScriptTestAssertion{ 5902 { 5903 Query: "call dolt_cherry_pick(hashof('branch1'));", 5904 Expected: []sql.Row{{"", 1, 0, 0}}, 5905 }, 5906 { 5907 Query: "select * from dolt_conflicts;", 5908 Expected: []sql.Row{{"t", uint64(1)}}, 5909 }, 5910 { 5911 Query: "select base_pk, base_v, our_pk, our_diff_type, their_pk, their_diff_type from dolt_conflicts_t;", 5912 Expected: []sql.Row{ 5913 {1, "uno", 1, "modified", 1, "modified"}, 5914 }, 5915 }, 5916 { 5917 Query: "insert into generated_foo values (2);", 5918 }, 5919 /* 5920 // TODO: https://github.com/dolthub/dolt/issues/7411 5921 // see below 5922 { 5923 Query: "insert into generated_bar values (2);", 5924 }, 5925 */ 5926 { 5927 Query: "call dolt_cherry_pick('--abort');", 5928 Expected: []sql.Row{{"", 0, 0, 0}}, 5929 }, 5930 { 5931 Query: "select * from dolt_conflicts;", 5932 Expected: []sql.Row{}, 5933 }, 5934 { 5935 Query: "select * from t;", 5936 Expected: []sql.Row{{1, "one"}}, 5937 }, 5938 { 5939 // An ignored table should still be present (and unstaged) after aborting the merge. 5940 Query: "select * from dolt_status;", 5941 Expected: []sql.Row{{"generated_foo", false, "new table"}}, 5942 }, 5943 { 5944 // Changes made to the table during the merge should not be reverted. 5945 Query: "select * from generated_foo;", 5946 Expected: []sql.Row{{1}, {2}}, 5947 }, 5948 /*{ 5949 // TODO: https://github.com/dolthub/dolt/issues/7411 5950 // The table that was force-added should be treated like any other table 5951 // and reverted to its state before the merge began. 5952 Query: "select * from generated_bar;", 5953 Expected: []sql.Row{{1}}, 5954 },*/ 5955 }, 5956 }, 5957 } 5958 5959 var DoltCommitTests = []queries.ScriptTest{ 5960 { 5961 Name: "CALL DOLT_COMMIT('-ALL') adds all tables (including new ones) to the commit.", 5962 SetUpScript: []string{ 5963 "CREATE table t (pk int primary key);", 5964 "INSERT INTO t VALUES (1);", 5965 "CALL DOLT_ADD('t');", 5966 "CALL DOLT_COMMIT('-m', 'add table t');", 5967 "CALL DOLT_RESET('--hard');", 5968 }, 5969 Assertions: []queries.ScriptTestAssertion{ 5970 { 5971 Query: "SELECT * from t;", 5972 Expected: []sql.Row{{1}}, 5973 }, 5974 // update a table 5975 { 5976 Query: "DELETE from t where pk = 1;", 5977 Expected: []sql.Row{{types.NewOkResult(1)}}, 5978 }, 5979 { 5980 Query: "CALL DOLT_COMMIT('-ALL', '-m', 'update table terminator');", 5981 Expected: []sql.Row{{doltCommit}}, 5982 }, 5983 // check last commit 5984 { 5985 Query: "select message from dolt_log limit 1", 5986 Expected: []sql.Row{{"update table terminator"}}, 5987 }, 5988 // amend last commit 5989 { 5990 Query: "CALL DOLT_COMMIT('-amend', '-m', 'update table t');", 5991 Expected: []sql.Row{{doltCommit}}, 5992 }, 5993 // check amended commit 5994 { 5995 Query: "SELECT * from t;", 5996 Expected: []sql.Row{}, 5997 }, 5998 { 5999 Query: "select message from dolt_log limit 1", 6000 Expected: []sql.Row{{"update table t"}}, 6001 }, 6002 { 6003 Query: "CALL DOLT_RESET('--hard');", 6004 Expected: []sql.Row{{0}}, 6005 }, 6006 { 6007 Query: "SELECT * from t;", 6008 Expected: []sql.Row{}, 6009 }, 6010 // delete a table 6011 { 6012 Query: "DROP TABLE t;", 6013 Expected: []sql.Row{{types.NewOkResult(0)}}, 6014 }, 6015 { 6016 Query: "CALL DOLT_COMMIT('-Am', 'drop table t');", 6017 Expected: []sql.Row{{doltCommit}}, 6018 }, 6019 { 6020 Query: "CALL DOLT_RESET('--hard');", 6021 Expected: []sql.Row{{0}}, 6022 }, 6023 { 6024 Query: "SELECT * from t;", 6025 ExpectedErr: sql.ErrTableNotFound, 6026 }, 6027 // create a table 6028 { 6029 Query: "CREATE table t2 (pk int primary key);", 6030 Expected: []sql.Row{{types.NewOkResult(0)}}, 6031 }, 6032 { 6033 Query: "CALL DOLT_COMMIT('-Am', 'add table 21');", 6034 Expected: []sql.Row{{doltCommit}}, 6035 }, 6036 // amend last commit 6037 { 6038 Query: "CALL DOLT_COMMIT('-amend', '-m', 'add table 2');", 6039 Expected: []sql.Row{{doltCommit}}, 6040 }, 6041 // check amended commit 6042 { 6043 Query: "select message from dolt_log limit 1", 6044 Expected: []sql.Row{{"add table 2"}}, 6045 }, 6046 { 6047 Query: "CALL DOLT_RESET('--hard');", 6048 Expected: []sql.Row{{0}}, 6049 }, 6050 { 6051 Query: "SELECT * from t2;", 6052 Expected: []sql.Row{}, 6053 }, 6054 }, 6055 }, 6056 { 6057 Name: "dolt commit works with arguments", 6058 SetUpScript: []string{ 6059 "CREATE table t (pk int primary key);", 6060 "INSERT INTO t VALUES (1);", 6061 "CALL DOLT_ADD('t');", 6062 "CALL DOLT_COMMIT('-m', concat('author: ','somebody'));", 6063 }, 6064 Assertions: []queries.ScriptTestAssertion{ 6065 { 6066 Query: "SELECT message from dolt_log where message = 'author: somebody'", 6067 Expected: []sql.Row{ 6068 {"author: somebody"}, 6069 }, 6070 }, 6071 }, 6072 }, 6073 { 6074 Name: "CALL DOLT_COMMIT('-amend') works to update commit message", 6075 SetUpScript: []string{ 6076 "SET @@AUTOCOMMIT=0;", 6077 "CREATE TABLE test (id INT PRIMARY KEY );", 6078 "INSERT INTO test (id) VALUES (2)", 6079 "CALL DOLT_ADD('.');", 6080 "CALL DOLT_COMMIT('-m', 'original commit message');", 6081 }, 6082 Assertions: []queries.ScriptTestAssertion{ 6083 { 6084 Query: "SELECT message FROM dolt_log;", 6085 Expected: []sql.Row{ 6086 {"original commit message"}, 6087 {"author: somebody"}, 6088 {"add table 2"}, 6089 {"drop table t"}, 6090 {"update table t"}, 6091 {"add table t"}, 6092 {"checkpoint enginetest database mydb"}, 6093 {"Initialize data repository"}, 6094 }, 6095 }, 6096 { 6097 Query: "SELECT to_id, from_id, diff_type FROM dolt_diff_test;", 6098 Expected: []sql.Row{{2, nil, "added"}}, 6099 }, 6100 { 6101 Query: "CALL DOLT_COMMIT('--amend', '-m', 'amended commit message');", 6102 Expected: []sql.Row{{doltCommit}}, 6103 }, 6104 { 6105 Query: "SELECT message FROM dolt_log;", 6106 Expected: []sql.Row{ 6107 {"amended commit message"}, 6108 {"author: somebody"}, 6109 {"add table 2"}, 6110 {"drop table t"}, 6111 {"update table t"}, 6112 {"add table t"}, 6113 {"checkpoint enginetest database mydb"}, 6114 {"Initialize data repository"}, 6115 }, 6116 }, 6117 { 6118 Query: "SELECT to_id, from_id, diff_type FROM dolt_diff_test;", 6119 Expected: []sql.Row{{2, nil, "added"}}, 6120 }, 6121 }, 6122 }, 6123 { 6124 Name: "CALL DOLT_COMMIT('-amend') works to add changes to a commit", 6125 SetUpScript: []string{ 6126 "SET @@AUTOCOMMIT=0;", 6127 "INSERT INTO test (id) VALUES (3)", 6128 "CALL DOLT_ADD('.');", 6129 "CALL DOLT_COMMIT('-m', 'original commit message for adding changes to a commit');", 6130 }, 6131 Assertions: []queries.ScriptTestAssertion{ 6132 { 6133 Query: "SELECT to_id, from_id, diff_type FROM dolt_diff_test;", 6134 Expected: []sql.Row{ 6135 {3, nil, "added"}, 6136 {2, nil, "added"}, 6137 }, 6138 }, 6139 { 6140 Query: "SELECT COUNT(*) FROM dolt_status;", 6141 Expected: []sql.Row{{0}}, 6142 }, 6143 { 6144 Query: "SELECT message FROM dolt_log;", 6145 Expected: []sql.Row{ 6146 {"original commit message for adding changes to a commit"}, 6147 {"amended commit message"}, 6148 {"author: somebody"}, 6149 {"add table 2"}, 6150 {"drop table t"}, 6151 {"update table t"}, 6152 {"add table t"}, 6153 {"checkpoint enginetest database mydb"}, 6154 {"Initialize data repository"}, 6155 }, 6156 }, 6157 { 6158 Query: "INSERT INTO test (id) VALUES (4)", 6159 Expected: []sql.Row{{types.NewOkResult(1)}}, 6160 }, 6161 { 6162 Query: "SELECT COUNT(*) FROM dolt_status;", 6163 Expected: []sql.Row{{1}}, 6164 }, 6165 { 6166 Query: "CALL DOLT_ADD('.');", 6167 Expected: []sql.Row{{0}}, 6168 }, 6169 { 6170 Query: "CALL DOLT_COMMIT('--amend');", 6171 Expected: []sql.Row{{doltCommit}}, 6172 }, 6173 { 6174 Query: "SELECT message FROM dolt_log;", 6175 Expected: []sql.Row{ 6176 {"original commit message for adding changes to a commit"}, 6177 {"amended commit message"}, 6178 {"author: somebody"}, 6179 {"add table 2"}, 6180 {"drop table t"}, 6181 {"update table t"}, 6182 {"add table t"}, 6183 {"checkpoint enginetest database mydb"}, 6184 {"Initialize data repository"}, 6185 }, 6186 }, 6187 { 6188 Query: "SELECT to_id, from_id, diff_type FROM dolt_diff_test;", 6189 Expected: []sql.Row{ 6190 {4, nil, "added"}, 6191 {3, nil, "added"}, 6192 {2, nil, "added"}, 6193 }, 6194 }, 6195 { 6196 Query: "INSERT INTO test (id) VALUES (5)", 6197 Expected: []sql.Row{{types.NewOkResult(1)}}, 6198 }, 6199 { 6200 Query: "SELECT COUNT(*) FROM dolt_status;", 6201 Expected: []sql.Row{{1}}, 6202 }, 6203 { 6204 Query: "CALL DOLT_ADD('.');", 6205 Expected: []sql.Row{{0}}, 6206 }, 6207 { 6208 Query: "CALL DOLT_COMMIT('--amend', '-m', 'amended commit with added changes');", 6209 Expected: []sql.Row{{doltCommit}}, 6210 }, 6211 { 6212 Query: "SELECT COUNT(*) FROM dolt_status;", 6213 Expected: []sql.Row{{0}}, 6214 }, 6215 { 6216 Query: "SELECT message FROM dolt_log;", 6217 Expected: []sql.Row{ 6218 {"amended commit with added changes"}, 6219 {"amended commit message"}, 6220 {"author: somebody"}, 6221 {"add table 2"}, 6222 {"drop table t"}, 6223 {"update table t"}, 6224 {"add table t"}, 6225 {"checkpoint enginetest database mydb"}, 6226 {"Initialize data repository"}, 6227 }, 6228 }, 6229 { 6230 Query: "SELECT to_id, from_id, diff_type FROM dolt_diff_test;", 6231 Expected: []sql.Row{ 6232 {5, nil, "added"}, 6233 {4, nil, "added"}, 6234 {3, nil, "added"}, 6235 {2, nil, "added"}, 6236 }, 6237 }, 6238 }, 6239 }, 6240 { 6241 Name: "CALL DOLT_COMMIT('-amend') works to remove changes from a commit", 6242 SetUpScript: []string{ 6243 "SET @@AUTOCOMMIT=0;", 6244 "INSERT INTO test (id) VALUES (6)", 6245 "INSERT INTO test (id) VALUES (7)", 6246 "CALL DOLT_ADD('.');", 6247 "CALL DOLT_COMMIT('-m', 'original commit message');", 6248 }, 6249 Assertions: []queries.ScriptTestAssertion{ 6250 { 6251 Query: "SELECT * FROM test;", 6252 Expected: []sql.Row{{2}, {3}, {4}, {5}, {6}, {7}}, 6253 }, 6254 { 6255 Query: "SELECT to_id, from_id, diff_type FROM dolt_diff_test;", 6256 Expected: []sql.Row{ 6257 {7, nil, "added"}, 6258 {6, nil, "added"}, 6259 {5, nil, "added"}, 6260 {4, nil, "added"}, 6261 {3, nil, "added"}, 6262 {2, nil, "added"}, 6263 }, 6264 }, 6265 { 6266 Query: "DELETE FROM test WHERE id = 6", 6267 Expected: []sql.Row{{types.NewOkResult(1)}}, 6268 }, 6269 { 6270 Query: "CALL DOLT_ADD('.');", 6271 Expected: []sql.Row{{0}}, 6272 }, 6273 { 6274 Query: "CALL DOLT_COMMIT('--amend', '-m', 'amended commit with removed changes');", 6275 Expected: []sql.Row{{doltCommit}}, 6276 }, 6277 { 6278 Query: "SELECT * FROM test;", 6279 Expected: []sql.Row{{2}, {3}, {4}, {5}, {7}}, 6280 }, 6281 { 6282 Query: "SELECT message FROM dolt_log;", 6283 Expected: []sql.Row{ 6284 {"amended commit with removed changes"}, 6285 {"amended commit with added changes"}, 6286 {"amended commit message"}, 6287 {"author: somebody"}, 6288 {"add table 2"}, 6289 {"drop table t"}, 6290 {"update table t"}, 6291 {"add table t"}, 6292 {"checkpoint enginetest database mydb"}, 6293 {"Initialize data repository"}, 6294 }, 6295 }, 6296 { 6297 Query: "SELECT to_id, from_id, diff_type FROM dolt_diff_test;", 6298 Expected: []sql.Row{ 6299 {7, nil, "added"}, 6300 {5, nil, "added"}, 6301 {4, nil, "added"}, 6302 {3, nil, "added"}, 6303 {2, nil, "added"}, 6304 }, 6305 }, 6306 }, 6307 }, 6308 { 6309 Name: "CALL DOLT_COMMIT('-amend') works to update a merge commit", 6310 SetUpScript: []string{ 6311 "SET @@AUTOCOMMIT=0;", 6312 6313 "CREATE TABLE test2 (id INT PRIMARY KEY, id2 INT);", 6314 "CALL DOLT_ADD('.');", 6315 "CALL DOLT_COMMIT('-m', 'original table');", 6316 6317 "CALL DOLT_CHECKOUT('-b','test-branch');", 6318 "INSERT INTO test2 (id, id2) VALUES (0, 2)", 6319 "CALL DOLT_ADD('.');", 6320 "CALL DOLT_COMMIT('-m', 'conflicting commit message');", 6321 6322 "CALL DOLT_CHECKOUT('main');", 6323 "INSERT INTO test2 (id, id2) VALUES (0, 1)", 6324 "CALL DOLT_ADD('.');", 6325 "CALL DOLT_COMMIT('-m', 'original commit message');", 6326 6327 "CALL DOLT_MERGE('test-branch');", 6328 "CALL DOLT_CONFLICTS_RESOLVE('--theirs', '.');", 6329 "CALL DOLT_COMMIT('-m', 'final merge');", 6330 }, 6331 Assertions: []queries.ScriptTestAssertion{ 6332 { 6333 Query: "CALL DOLT_COMMIT('--amend', '-m', 'new merge');", 6334 Expected: []sql.Row{{doltCommit}}, 6335 }, 6336 { 6337 Query: "SELECT message FROM dolt_log;", 6338 Expected: []sql.Row{ 6339 {"new merge"}, 6340 {"original commit message"}, 6341 {"conflicting commit message"}, 6342 {"original table"}, 6343 {"amended commit with removed changes"}, 6344 {"amended commit with added changes"}, 6345 {"amended commit message"}, 6346 {"author: somebody"}, 6347 {"add table 2"}, 6348 {"drop table t"}, 6349 {"update table t"}, 6350 {"add table t"}, 6351 {"checkpoint enginetest database mydb"}, 6352 {"Initialize data repository"}, 6353 }, 6354 }, 6355 { 6356 Query: "SET @hash=(SELECT commit_hash FROM dolt_log LIMIT 1);", 6357 Expected: []sql.Row{{}}, 6358 }, 6359 { 6360 Query: "SELECT COUNT(parent_hash) FROM dolt_commit_ancestors WHERE commit_hash= @hash;", 6361 Expected: []sql.Row{{2}}, 6362 }, 6363 }, 6364 }, 6365 } 6366 6367 var DoltIndexPrefixScripts = []queries.ScriptTest{ 6368 { 6369 Name: "inline secondary indexes with collation", 6370 SetUpScript: []string{ 6371 "create table t (i int primary key, v1 varchar(10), v2 varchar(10), unique index (v1(3),v2(5))) collate utf8mb4_0900_ai_ci", 6372 }, 6373 Assertions: []queries.ScriptTestAssertion{ 6374 { 6375 Query: "show create table t", 6376 Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` int NOT NULL,\n `v1` varchar(10),\n `v2` varchar(10),\n PRIMARY KEY (`i`),\n UNIQUE KEY `v1v2` (`v1`(3),`v2`(5))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"}}, 6377 }, 6378 { 6379 Query: "insert into t values (0, 'a', 'a'), (1, 'ab','ab'), (2, 'abc', 'abc'), (3, 'abcde', 'abcde')", 6380 Expected: []sql.Row{{types.NewOkResult(4)}}, 6381 }, 6382 { 6383 Query: "insert into t values (99, 'ABC', 'ABCDE')", 6384 ExpectedErr: sql.ErrUniqueKeyViolation, 6385 }, 6386 { 6387 Query: "insert into t values (99, 'ABC', 'ABCDE')", 6388 ExpectedErrStr: "duplicate unique key given: [ABC,ABCDE]", 6389 }, 6390 { 6391 Query: "insert into t values (99, 'ABC123', 'ABCDE123')", 6392 ExpectedErr: sql.ErrUniqueKeyViolation, 6393 }, 6394 { 6395 Query: "insert into t values (99, 'ABC123', 'ABCDE123')", 6396 ExpectedErrStr: "duplicate unique key given: [ABC,ABCDE]", 6397 }, 6398 { 6399 Query: "select * from t where v1 = 'A'", 6400 Expected: []sql.Row{ 6401 {0, "a", "a"}, 6402 }, 6403 }, 6404 { 6405 Query: "select * from t where v1 = 'ABC'", 6406 Expected: []sql.Row{ 6407 {2, "abc", "abc"}, 6408 }, 6409 }, 6410 { 6411 Query: "select * from t where v1 = 'ABCD'", 6412 Expected: []sql.Row{}, 6413 }, 6414 { 6415 Query: "select * from t where v1 > 'A' and v1 < 'ABCDE'", 6416 Expected: []sql.Row{ 6417 {1, "ab", "ab"}, 6418 {2, "abc", "abc"}, 6419 }, 6420 }, 6421 { 6422 Query: "select * from t where v1 > 'A' and v2 < 'ABCDE'", 6423 Expected: []sql.Row{ 6424 {1, "ab", "ab"}, 6425 {2, "abc", "abc"}, 6426 }, 6427 }, 6428 { 6429 Query: "update t set v1 = concat(v1, 'Z') where v1 >= 'A'", 6430 Expected: []sql.Row{ 6431 {types.OkResult{RowsAffected: 4, InsertID: 0, Info: plan.UpdateInfo{Matched: 4, Updated: 4}}}, 6432 }, 6433 }, 6434 { 6435 Query: "select * from t", 6436 Expected: []sql.Row{ 6437 {0, "aZ", "a"}, 6438 {1, "abZ", "ab"}, 6439 {2, "abcZ", "abc"}, 6440 {3, "abcdeZ", "abcde"}, 6441 }, 6442 }, 6443 { 6444 Query: "delete from t where v1 >= 'A'", 6445 Expected: []sql.Row{ 6446 {types.OkResult{RowsAffected: 4}}, 6447 }, 6448 }, 6449 { 6450 Query: "select * from t", 6451 Expected: []sql.Row{}, 6452 }, 6453 }, 6454 }, 6455 // TODO: these should eventually go in GMS, but it doesn't currently support index rewrite on column modify 6456 { 6457 Name: "drop prefix lengths when modifying column to non string type", 6458 SetUpScript: []string{ 6459 "create table t (j varchar(100), index (j(10)))", 6460 }, 6461 Assertions: []queries.ScriptTestAssertion{ 6462 { 6463 Query: "alter table t modify column j int", 6464 Expected: []sql.Row{{types.OkResult{}}}, 6465 }, 6466 { 6467 Query: "show create table t", 6468 Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `j` int,\n KEY `j` (`j`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 6469 }, 6470 }, 6471 }, 6472 { 6473 Name: "drop prefix length when modifying columns to invalid string type", 6474 SetUpScript: []string{ 6475 "create table t (j varchar(100), index (j(10)))", 6476 }, 6477 Assertions: []queries.ScriptTestAssertion{ 6478 { 6479 Query: "alter table t modify column j varchar(2)", 6480 Expected: []sql.Row{{types.OkResult{}}}, 6481 }, 6482 { 6483 Query: "show create table t", 6484 Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `j` varchar(2),\n KEY `j` (`j`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 6485 }, 6486 }, 6487 }, 6488 { 6489 Name: "preserve prefix length when modifying column to valid string type", 6490 SetUpScript: []string{ 6491 "create table t (j varchar(100), index (j(10)))", 6492 }, 6493 Assertions: []queries.ScriptTestAssertion{ 6494 { 6495 Query: "alter table t modify column j varchar(200)", 6496 Expected: []sql.Row{{types.OkResult{}}}, 6497 }, 6498 { 6499 Query: "show create table t", 6500 Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `j` varchar(200),\n KEY `j` (`j`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 6501 }, 6502 }, 6503 }, 6504 { 6505 Name: "preserve prefix lengths when there are other unchanged prefix lengths", 6506 SetUpScript: []string{ 6507 "create table t (i varchar(100), j varchar(100), index (i(10), j(10)))", 6508 }, 6509 Assertions: []queries.ScriptTestAssertion{ 6510 { 6511 Query: "alter table t modify column j int", 6512 Expected: []sql.Row{{types.OkResult{}}}, 6513 }, 6514 { 6515 Query: "show create table t", 6516 Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n `i` varchar(100),\n `j` int,\n KEY `ij` (`i`(10),`j`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 6517 }, 6518 }, 6519 }, 6520 { 6521 Name: "prefix length too long", 6522 SetUpScript: []string{ 6523 "create table t (i blob, index(i(3072)))", 6524 }, 6525 Assertions: []queries.ScriptTestAssertion{ 6526 { 6527 Query: "alter table t modify column i text", 6528 ExpectedErr: sql.ErrKeyTooLong, 6529 }, 6530 }, 6531 }, 6532 } 6533 6534 // DoltCallAsOf are tests of using CALL ... AS OF using commits 6535 var DoltCallAsOf = []queries.ScriptTest{ 6536 { 6537 Name: "Database syntax properly handles inter-CALL communication", 6538 SetUpScript: []string{ 6539 `CREATE PROCEDURE p1() 6540 BEGIN 6541 DECLARE str VARCHAR(20); 6542 CALL p2(str); 6543 SET str = CONCAT('a', str); 6544 SELECT str; 6545 END`, 6546 `CREATE PROCEDURE p2(OUT param VARCHAR(20)) 6547 BEGIN 6548 SET param = 'b'; 6549 END`, 6550 "CALL DOLT_ADD('-A');", 6551 "CALL DOLT_COMMIT('-m', 'First procedures');", 6552 "CALL DOLT_BRANCH('p12');", 6553 "DROP PROCEDURE p1;", 6554 "DROP PROCEDURE p2;", 6555 `CREATE PROCEDURE p1() 6556 BEGIN 6557 DECLARE str VARCHAR(20); 6558 CALL p2(str); 6559 SET str = CONCAT('c', str); 6560 SELECT str; 6561 END`, 6562 `CREATE PROCEDURE p2(OUT param VARCHAR(20)) 6563 BEGIN 6564 SET param = 'd'; 6565 END`, 6566 "CALL DOLT_ADD('-A');", 6567 "CALL DOLT_COMMIT('-m', 'Second procedures');", 6568 }, 6569 Assertions: []queries.ScriptTestAssertion{ 6570 { 6571 Query: "CALL p1();", 6572 Expected: []sql.Row{{"cd"}}, 6573 }, 6574 { 6575 Query: "CALL `mydb/main`.p1();", 6576 Expected: []sql.Row{{"cd"}}, 6577 }, 6578 { 6579 Query: "CALL `mydb/p12`.p1();", 6580 Expected: []sql.Row{{"ab"}}, 6581 }, 6582 }, 6583 }, 6584 { 6585 Name: "CALL ... AS OF references historic data through nested calls", 6586 SetUpScript: []string{ 6587 "CREATE TABLE test (v1 BIGINT);", 6588 "INSERT INTO test VALUES (1);", 6589 `CREATE PROCEDURE p1() 6590 BEGIN 6591 CALL p2(); 6592 END`, 6593 `CREATE PROCEDURE p2() 6594 BEGIN 6595 SELECT * FROM test; 6596 END`, 6597 "CALL DOLT_ADD('-A');", 6598 "CALL DOLT_COMMIT('-m', 'commit message');", 6599 "UPDATE test SET v1 = 2;", 6600 "CALL DOLT_ADD('-A');", 6601 "CALL DOLT_COMMIT('-m', 'commit message');", 6602 "UPDATE test SET v1 = 3;", 6603 "CALL DOLT_ADD('-A');", 6604 "CALL DOLT_COMMIT('-m', 'commit message');", 6605 "UPDATE test SET v1 = 4;", 6606 "CALL DOLT_ADD('-A');", 6607 "CALL DOLT_COMMIT('-m', 'commit message');", 6608 }, 6609 Assertions: []queries.ScriptTestAssertion{ 6610 { 6611 Query: "CALL p1();", 6612 Expected: []sql.Row{{4}}, 6613 }, 6614 { 6615 Query: "CALL p1() AS OF 'HEAD';", 6616 Expected: []sql.Row{{4}}, 6617 }, 6618 { 6619 Query: "CALL p1() AS OF 'HEAD~1';", 6620 Expected: []sql.Row{{3}}, 6621 }, 6622 { 6623 Query: "CALL p1() AS OF 'HEAD~2';", 6624 Expected: []sql.Row{{2}}, 6625 }, 6626 { 6627 Query: "CALL p1() AS OF 'HEAD~3';", 6628 Expected: []sql.Row{{1}}, 6629 }, 6630 }, 6631 }, 6632 { 6633 Name: "CALL ... AS OF doesn't overwrite nested CALL ... AS OF", 6634 SetUpScript: []string{ 6635 "CREATE TABLE myhistorytable (pk BIGINT PRIMARY KEY, s TEXT);", 6636 "INSERT INTO myhistorytable VALUES (1, 'first row, 1'), (2, 'second row, 1'), (3, 'third row, 1');", 6637 "CREATE PROCEDURE p1() BEGIN CALL p2(); END", 6638 "CREATE PROCEDURE p1a() BEGIN CALL p2() AS OF 'HEAD~2'; END", 6639 "CREATE PROCEDURE p1b() BEGIN CALL p2a(); END", 6640 "CREATE PROCEDURE p2() BEGIN SELECT * FROM myhistorytable; END", 6641 "CALL DOLT_ADD('-A');", 6642 "CALL DOLT_COMMIT('-m', 'commit message');", 6643 "DELETE FROM myhistorytable;", 6644 "INSERT INTO myhistorytable VALUES (1, 'first row, 2'), (2, 'second row, 2'), (3, 'third row, 2');", 6645 "CALL DOLT_ADD('-A');", 6646 "CALL DOLT_COMMIT('-m', 'commit message');", 6647 "DROP TABLE myhistorytable;", 6648 "CREATE TABLE myhistorytable (pk BIGINT PRIMARY KEY, s TEXT, c TEXT);", 6649 "INSERT INTO myhistorytable VALUES (1, 'first row, 3', '1'), (2, 'second row, 3', '2'), (3, 'third row, 3', '3');", 6650 "CREATE PROCEDURE p2a() BEGIN SELECT * FROM myhistorytable AS OF 'HEAD~1'; END", 6651 "CALL DOLT_ADD('-A');", 6652 "CALL DOLT_COMMIT('-m', 'commit message');", 6653 }, 6654 Assertions: []queries.ScriptTestAssertion{ 6655 { 6656 Query: "CALL p1();", 6657 Expected: []sql.Row{ 6658 {int64(1), "first row, 3", "1"}, 6659 {int64(2), "second row, 3", "2"}, 6660 {int64(3), "third row, 3", "3"}, 6661 }, 6662 }, 6663 { 6664 Query: "CALL p1a();", 6665 Expected: []sql.Row{ 6666 {int64(1), "first row, 1"}, 6667 {int64(2), "second row, 1"}, 6668 {int64(3), "third row, 1"}, 6669 }, 6670 }, 6671 { 6672 Query: "CALL p1b();", 6673 Expected: []sql.Row{ 6674 {int64(1), "first row, 2"}, 6675 {int64(2), "second row, 2"}, 6676 {int64(3), "third row, 2"}, 6677 }, 6678 }, 6679 { 6680 Query: "CALL p2();", 6681 Expected: []sql.Row{ 6682 {int64(1), "first row, 3", "1"}, 6683 {int64(2), "second row, 3", "2"}, 6684 {int64(3), "third row, 3", "3"}, 6685 }, 6686 }, 6687 { 6688 Query: "CALL p2a();", 6689 Expected: []sql.Row{ 6690 {int64(1), "first row, 2"}, 6691 {int64(2), "second row, 2"}, 6692 {int64(3), "third row, 2"}, 6693 }, 6694 }, 6695 { 6696 Query: "CALL p1() AS OF 'HEAD~2';", 6697 Expected: []sql.Row{ 6698 {int64(1), "first row, 1"}, 6699 {int64(2), "second row, 1"}, 6700 {int64(3), "third row, 1"}, 6701 }, 6702 }, 6703 { 6704 Query: "CALL p1a() AS OF 'HEAD';", 6705 Expected: []sql.Row{ 6706 {int64(1), "first row, 1"}, 6707 {int64(2), "second row, 1"}, 6708 {int64(3), "third row, 1"}, 6709 }, 6710 }, 6711 { 6712 Query: "CALL p1b() AS OF 'HEAD';", 6713 Expected: []sql.Row{ 6714 {int64(1), "first row, 2"}, 6715 {int64(2), "second row, 2"}, 6716 {int64(3), "third row, 2"}, 6717 }, 6718 }, 6719 { 6720 Query: "CALL p2() AS OF 'HEAD~2';", 6721 Expected: []sql.Row{ 6722 {int64(1), "first row, 1"}, 6723 {int64(2), "second row, 1"}, 6724 {int64(3), "third row, 1"}, 6725 }, 6726 }, 6727 { 6728 Query: "CALL p2a() AS OF 'HEAD';", 6729 Expected: []sql.Row{ 6730 {int64(1), "first row, 2"}, 6731 {int64(2), "second row, 2"}, 6732 {int64(3), "third row, 2"}, 6733 }, 6734 }, 6735 }, 6736 }, 6737 { 6738 Name: "CALL ... AS OF errors if attempting to modify a table", 6739 SetUpScript: []string{ 6740 "CREATE TABLE test (v1 BIGINT);", 6741 "INSERT INTO test VALUES (2);", 6742 "CALL DOLT_ADD('-A');", 6743 "CALL DOLT_COMMIT('-m', 'commit message');", 6744 `CREATE PROCEDURE p1() 6745 BEGIN 6746 UPDATE test SET v1 = v1 * 2; 6747 END`, 6748 "CALL DOLT_ADD('-A');", 6749 "CALL DOLT_COMMIT('-m', 'commit message');", 6750 }, 6751 Assertions: []queries.ScriptTestAssertion{ 6752 { 6753 Query: "SELECT * FROM test;", 6754 Expected: []sql.Row{{2}}, 6755 }, 6756 { 6757 Query: "CALL p1();", 6758 Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, 6759 }, 6760 { 6761 Query: "SELECT * FROM test;", 6762 Expected: []sql.Row{{4}}, 6763 }, 6764 { 6765 Query: "CALL p1() AS OF 'HEAD~1';", 6766 ExpectedErr: sql.ErrProcedureCallAsOfReadOnly, 6767 }, 6768 }, 6769 }, 6770 { 6771 Name: "Database syntax propogates to inner calls", 6772 SetUpScript: []string{ 6773 "CALL DOLT_CHECKOUT('main');", 6774 `CREATE PROCEDURE p4() 6775 BEGIN 6776 CALL p5(); 6777 END`, 6778 `CREATE PROCEDURE p5() 6779 BEGIN 6780 SELECT 3; 6781 END`, 6782 "CALL DOLT_ADD('-A');", 6783 "CALL DOLT_COMMIT('-m', 'commit message');", 6784 "CALL DOLT_BRANCH('p45');", 6785 "DROP PROCEDURE p4;", 6786 "DROP PROCEDURE p5;", 6787 `CREATE PROCEDURE p4() 6788 BEGIN 6789 CALL p5(); 6790 END`, 6791 `CREATE PROCEDURE p5() 6792 BEGIN 6793 SELECT 4; 6794 END`, 6795 "CALL DOLT_ADD('-A');", 6796 "CALL DOLT_COMMIT('-m', 'commit message');", 6797 }, 6798 Assertions: []queries.ScriptTestAssertion{ 6799 { 6800 Query: "CALL p4();", 6801 Expected: []sql.Row{{4}}, 6802 }, 6803 { 6804 Query: "CALL p5();", 6805 Expected: []sql.Row{{4}}, 6806 }, 6807 { 6808 Query: "CALL `mydb/main`.p4();", 6809 Expected: []sql.Row{{4}}, 6810 }, 6811 { 6812 Query: "CALL `mydb/main`.p5();", 6813 Expected: []sql.Row{{4}}, 6814 }, 6815 { 6816 Query: "CALL `mydb/p45`.p4();", 6817 Expected: []sql.Row{{3}}, 6818 }, 6819 { 6820 Query: "CALL `mydb/p45`.p5();", 6821 Expected: []sql.Row{{3}}, 6822 }, 6823 }, 6824 }, 6825 { 6826 Name: "Database syntax with AS OF", 6827 SetUpScript: []string{ 6828 "CREATE TABLE test (v1 BIGINT);", 6829 "INSERT INTO test VALUES (2);", 6830 `CREATE PROCEDURE p1() 6831 BEGIN 6832 SELECT v1 * 10 FROM test; 6833 END`, 6834 "CALL DOLT_ADD('-A');", 6835 "CALL DOLT_COMMIT('-m', 'commit message');", 6836 "CALL DOLT_BRANCH('other');", 6837 "DROP PROCEDURE p1;", 6838 `CREATE PROCEDURE p1() 6839 BEGIN 6840 SELECT v1 * 100 FROM test; 6841 END`, 6842 "UPDATE test SET v1 = 3;", 6843 "CALL DOLT_ADD('-A');", 6844 "CALL DOLT_COMMIT('-m', 'commit message');", 6845 }, 6846 Assertions: []queries.ScriptTestAssertion{ 6847 { 6848 Query: "CALL p1();", 6849 Expected: []sql.Row{{300}}, 6850 }, 6851 { 6852 Query: "CALL `mydb/main`.p1();", 6853 Expected: []sql.Row{{300}}, 6854 }, 6855 { 6856 Query: "CALL `mydb/other`.p1();", 6857 Expected: []sql.Row{{30}}, 6858 }, 6859 { 6860 Query: "CALL p1() AS OF 'HEAD';", 6861 Expected: []sql.Row{{300}}, 6862 }, 6863 { 6864 Query: "CALL `mydb/main`.p1() AS OF 'HEAD';", 6865 Expected: []sql.Row{{300}}, 6866 }, 6867 { 6868 Query: "CALL `mydb/other`.p1() AS OF 'HEAD';", 6869 Expected: []sql.Row{{30}}, 6870 }, 6871 { 6872 Query: "CALL p1() AS OF 'HEAD~1';", 6873 Expected: []sql.Row{{200}}, 6874 }, 6875 { 6876 Query: "CALL `mydb/main`.p1() AS OF 'HEAD~1';", 6877 Expected: []sql.Row{{200}}, 6878 }, 6879 { 6880 Query: "CALL `mydb/other`.p1() AS OF 'HEAD~1';", 6881 Expected: []sql.Row{{20}}, 6882 }, 6883 }, 6884 }, 6885 } 6886 6887 var DoltSystemVariables = []queries.ScriptTest{ 6888 { 6889 Name: "DOLT_SHOW_SYSTEM_TABLES", 6890 SetUpScript: []string{ 6891 "CREATE TABLE test (pk int PRIMARY KEY);", 6892 "SET @@DOLT_SHOW_SYSTEM_TABLES=1", 6893 }, 6894 Assertions: []queries.ScriptTestAssertion{ 6895 { 6896 Query: "SHOW TABLES;", 6897 Expected: []sql.Row{ 6898 {"dolt_branches"}, 6899 {"dolt_commit_ancestors"}, 6900 {"dolt_commit_diff_test"}, 6901 {"dolt_commits"}, 6902 {"dolt_conflicts"}, 6903 {"dolt_conflicts_test"}, 6904 {"dolt_constraint_violations"}, 6905 {"dolt_constraint_violations_test"}, 6906 {"dolt_diff_test"}, 6907 {"dolt_history_test"}, 6908 {"dolt_log"}, 6909 {"dolt_remote_branches"}, 6910 {"dolt_remotes"}, 6911 {"dolt_status"}, 6912 {"test"}, 6913 }, 6914 }, 6915 }, 6916 }, 6917 }