github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/sqle/enginetest/dolt_queries_merge.go (about) 1 // Copyright 2022 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 "regexp" 19 "strings" 20 21 "github.com/dolthub/go-mysql-server/enginetest" 22 "github.com/dolthub/go-mysql-server/enginetest/queries" 23 "github.com/dolthub/go-mysql-server/sql" 24 "github.com/dolthub/go-mysql-server/sql/plan" 25 "github.com/dolthub/go-mysql-server/sql/types" 26 "gopkg.in/src-d/go-errors.v1" 27 28 "github.com/dolthub/dolt/go/libraries/doltcore/merge" 29 "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" 30 ) 31 32 type MergeScriptTest struct { 33 // Name of the script test 34 Name string 35 // The sql statements to generate the ancestor commit 36 AncSetUpScript []string 37 // The sql statements to generate the right commit 38 RightSetUpScript []string 39 // The sql statements to generate the left commit 40 LeftSetUpScript []string 41 // The set of assertions to make after setup, in order 42 Assertions []queries.ScriptTestAssertion 43 // For tests that make a single assertion, Query can be set for the single assertion 44 Query string 45 // For tests that make a single assertion, Expected can be set for the single assertion 46 Expected []sql.Row 47 // For tests that make a single assertion, ExpectedErr can be set for the expected error 48 ExpectedErr *errors.Kind 49 // SkipPrepared is true when we skip a test for prepared statements only 50 SkipPrepared bool 51 } 52 53 type doltCommitValidator struct{} 54 55 var _ enginetest.CustomValueValidator = &doltCommitValidator{} 56 var hashRegex = regexp.MustCompile(`^[0-9a-v]{32}$`) 57 58 func (dcv *doltCommitValidator) Validate(val interface{}) (bool, error) { 59 hash, ok := val.(string) 60 if !ok { 61 return false, nil 62 } 63 return hashRegex.MatchString(hash), nil 64 } 65 66 var doltCommit = &doltCommitValidator{} 67 68 var MergeScripts = []queries.ScriptTest{ 69 { 70 // https://github.com/dolthub/dolt/issues/7275 71 Name: "keyless table merge with constraint violations", 72 SetUpScript: []string{ 73 "CREATE TABLE aTable (aColumn INT NULL, bColumn INT NULL, UNIQUE INDEX aColumn_UNIQUE (aColumn ASC) VISIBLE, UNIQUE INDEX bColumn_UNIQUE (bColumn ASC) VISIBLE);", 74 "CALL dolt_commit('-Am', 'add tables');", 75 "CALL dolt_checkout('-b', 'side');", 76 "INSERT INTO aTable VALUES (1,2);", 77 "CALL dolt_commit('-am', 'add side data');", 78 79 "CALL dolt_checkout('main');", 80 "INSERT INTO aTable VALUES (1,3);", 81 "CALL dolt_commit('-am', 'add main data');", 82 "CALL dolt_checkout('side');", 83 "SET @@dolt_force_transaction_commit=1;", 84 }, 85 Assertions: []queries.ScriptTestAssertion{ 86 { 87 Query: "SELECT * FROM aTable;", 88 Expected: []sql.Row{{1, 2}}, 89 }, 90 { 91 Query: "call dolt_merge('main');", 92 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 93 }, 94 { 95 Query: "SELECT * FROM aTable;", 96 Expected: []sql.Row{{1, 2}, {1, 3}}, 97 }, 98 { 99 Query: "SELECT * FROM dolt_constraint_violations;", 100 Expected: []sql.Row{{"aTable", uint64(2)}}, 101 }, 102 { 103 Query: "SELECT from_root_ish, violation_type, hex(dolt_row_hash), aColumn, bColumn, CAST(violation_info as CHAR) FROM dolt_constraint_violations_aTable;", 104 Expected: []sql.Row{ 105 {doltCommit, "unique index", "5A1ED8633E1842FCA8EE529E4F1C5944", 1, 2, `{"Columns":["aColumn"],"Name":"aColumn_UNIQUE"}`}, 106 {doltCommit, "unique index", "A922BFBF4E5489501A3808BC5CD702C0", 1, 3, `{"Columns":["aColumn"],"Name":"aColumn_UNIQUE"}`}, 107 }, 108 }, 109 { 110 // Fix the data 111 Query: "UPDATE aTable SET aColumn = 2 WHERE bColumn = 2;", 112 Expected: []sql.Row{{types.OkResult{RowsAffected: uint64(1), Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, 113 }, 114 { 115 // clear out the violations 116 Query: "DELETE FROM dolt_constraint_violations_aTable;", 117 Expected: []sql.Row{{types.NewOkResult(2)}}, 118 }, 119 { 120 // Commit the merge after resolving the constraint violations 121 Query: "call dolt_commit('-am', 'merging in main and resolving unique constraint violations');", 122 Expected: []sql.Row{{doltCommit}}, 123 }, 124 { 125 // Merging again is a no-op 126 Query: "call dolt_merge('main');", 127 Expected: []sql.Row{{"", 0, 0, "cannot fast forward from a to b. a is ahead of b already"}}, 128 }, 129 }, 130 }, 131 132 { 133 // When there is a constraint violation for duplicate copies of a row in a keyless table, each row 134 // will violate constraint in exactly the same way. Currently, the dolt_constraint_violations_<table> 135 // system table will only contain one row for each unique violation. In other words, there may be N 136 // duplicate rows in the keyless table that violate the constraint, but only one row is shown in the 137 // constraint system table representing them all. 138 // TODO: We could add a new column to the PK for the constraints table to represent a unique ID/count 139 // for the duplicate rows, and then we could support a 1:1 mapping of rows in the keyless table 140 // to rows in the constraint violation system table. 141 Name: "keyless table merge with constraint violation on duplicate rows", 142 SetUpScript: []string{ 143 "CREATE TABLE parent (pk INT primary key);", 144 "insert into parent values (1), (2);", 145 "CREATE TABLE aTable (aColumn INT NULL, bColumn INT NULL);", 146 "INSERT INTO aTable VALUES (1, 1);", 147 "CALL dolt_commit('-Am', 'add tables');", 148 149 "CALL dolt_checkout('-b', 'side');", 150 "INSERT INTO aTable VALUES (2, -1), (2, -1);", 151 "CALL dolt_commit('-am', 'add side data');", 152 153 "CALL dolt_checkout('main');", 154 "ALTER TABLE aTable add foreign key (bColumn) references parent(pk);", 155 "CALL dolt_commit('-am', 'add main data');", 156 "CALL dolt_checkout('side');", 157 "SET @@dolt_force_transaction_commit=1;", 158 }, 159 Assertions: []queries.ScriptTestAssertion{ 160 { 161 Query: "SELECT * FROM aTable ORDER BY aColumn;", 162 Expected: []sql.Row{{1, 1}, {2, -1}, {2, -1}}, 163 }, 164 { 165 Query: "call dolt_merge('main');", 166 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 167 }, 168 { 169 Query: "SELECT * FROM aTable ORDER BY aColumn;", 170 Expected: []sql.Row{{1, 1}, {2, -1}, {2, -1}}, 171 }, 172 { 173 Query: "SELECT * FROM dolt_constraint_violations;", 174 Expected: []sql.Row{{"aTable", uint64(1)}}, 175 }, 176 { 177 Query: "SELECT from_root_ish, violation_type, hex(dolt_row_hash), aColumn, bColumn, CAST(violation_info as CHAR) FROM dolt_constraint_violations_aTable;", 178 Expected: []sql.Row{ 179 {doltCommit, "foreign key", "13F8480978D0556FA9AE6DF5745A7ACA", 2, -1, `{"Columns":["bColumn"],"ForeignKey":"atable_ibfk_1","Index":"bColumn","OnDelete":"RESTRICT","OnUpdate":"RESTRICT","ReferencedColumns":["pk"],"ReferencedIndex":"","ReferencedTable":"parent","Table":"aTable"}`}, 180 }, 181 }, 182 { 183 // Fix the data 184 Query: "UPDATE aTable SET bColumn = 2 WHERE bColumn = -1;", 185 Expected: []sql.Row{{types.OkResult{RowsAffected: uint64(2), Info: plan.UpdateInfo{Matched: 2, Updated: 2}}}}, 186 }, 187 { 188 // clear out the violations 189 Query: "DELETE FROM dolt_constraint_violations_aTable;", 190 Expected: []sql.Row{{types.NewOkResult(1)}}, 191 }, 192 { 193 // Commit the merge after resolving the constraint violations 194 Query: "call dolt_commit('-am', 'merging in main and resolving unique constraint violations');", 195 Expected: []sql.Row{{doltCommit}}, 196 }, 197 { 198 // Merging again is a no-op 199 Query: "call dolt_merge('main');", 200 Expected: []sql.Row{{"", 0, 0, "cannot fast forward from a to b. a is ahead of b already"}}, 201 }, 202 }, 203 }, 204 { 205 // Unique checks should not include the content of deleted rows in checks. Tests two updates: one triggers 206 // going from a smaller key to a higher key, and one going from a higher key to a smaller key (in order to test 207 // delete/insert events in either order). https://github.com/dolthub/dolt/issues/6319 208 Name: "unique constraint checks do not consider deleted rows", 209 SetUpScript: []string{ 210 "set @@autocommit=0;", 211 "create table tableA (pk varchar(255) primary key, col1 varchar(255),UNIQUE KEY unique1 (col1))", 212 "insert into tableA values ('B', '1'), ('C', 2), ('Y', '100')", 213 "call dolt_commit('-Am', 'creating table');", 214 "call dolt_branch('feature');", 215 "update tableA set pk = 'A' where pk='B';", 216 "update tableA set pk = 'Z' where pk='Y';", 217 "call dolt_commit('-am', 'update two rows');", 218 "call dolt_checkout('feature');", 219 "update tableA set col1='C' where pk='C';", 220 "call dolt_commit('-am', 'added row on branch feature');", 221 }, 222 Assertions: []queries.ScriptTestAssertion{ 223 { 224 Query: "call dolt_merge('main');", 225 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 226 }, 227 { 228 Query: "select * from dolt_constraint_violations;", 229 Expected: []sql.Row{}, 230 }, 231 { 232 Query: "select * from dolt_constraint_violations_tableA;", 233 Expected: []sql.Row{}, 234 }, 235 { 236 Query: "select * from tableA;", 237 Expected: []sql.Row{{"A", "1"}, {"C", "C"}, {"Z", "100"}}, 238 }, 239 }, 240 }, 241 { 242 Name: "CALL DOLT_MERGE ff correctly works with autocommit off", 243 SetUpScript: []string{ 244 "CREATE TABLE test (pk int primary key)", 245 "call DOLT_ADD('.')", 246 "INSERT INTO test VALUES (0),(1),(2);", 247 "SET autocommit = 0", 248 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 249 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 250 "INSERT INTO test VALUES (3);", 251 "UPDATE test SET pk=1000 WHERE pk=0;", 252 "CALL DOLT_ADD('.');", 253 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", 254 "CALL DOLT_CHECKOUT('main');", 255 }, 256 Assertions: []queries.ScriptTestAssertion{ 257 { 258 // FF-Merge 259 Query: "CALL DOLT_MERGE('feature-branch')", 260 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 261 }, 262 { 263 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 264 Expected: []sql.Row{{false, nil, nil, nil}}, 265 }, 266 { 267 Query: "SELECT * from dolt_status", 268 Expected: []sql.Row{}, 269 }, 270 { 271 Query: "CALL DOLT_CHECKOUT('-b', 'new-branch')", 272 Expected: []sql.Row{{0, "Switched to branch 'new-branch'"}}, 273 }, 274 { 275 Query: "INSERT INTO test VALUES (4)", 276 Expected: []sql.Row{{types.NewOkResult(1)}}, 277 }, 278 }, 279 }, 280 { 281 Name: "CALL DOLT_MERGE ff correctly works with autocommit off, no checkout", 282 SetUpScript: []string{ 283 "CREATE TABLE test (pk int primary key)", 284 "call DOLT_ADD('.')", 285 "INSERT INTO test VALUES (0),(1),(2);", 286 "SET autocommit = 0", 287 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 288 "CALL DOLT_BRANCH('feature-branch')", 289 "use `mydb/feature-branch`", 290 "INSERT INTO test VALUES (3);", 291 "UPDATE test SET pk=1000 WHERE pk=0;", 292 "CALL DOLT_ADD('.');", 293 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", 294 "use mydb/main;", 295 }, 296 Assertions: []queries.ScriptTestAssertion{ 297 { 298 // FF-Merge 299 Query: "CALL DOLT_MERGE('feature-branch')", 300 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 301 }, 302 { 303 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 304 Expected: []sql.Row{{false, nil, nil, nil}}, 305 }, 306 { 307 Query: "SELECT * from dolt_status", 308 Expected: []sql.Row{}, 309 }, 310 { 311 Query: "select * from test order by 1", 312 Expected: []sql.Row{ 313 {1}, {2}, {3}, {1000}, 314 }, 315 }, 316 }, 317 }, 318 { 319 Name: "CALL DOLT_MERGE fails on non-branch revision", 320 SetUpScript: []string{ 321 "CREATE TABLE test (pk int primary key)", 322 "call DOLT_ADD('.')", 323 "INSERT INTO test VALUES (0),(1),(2);", 324 "SET autocommit = 0", 325 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 326 "CALL DOLT_BRANCH('feature-branch')", 327 "use `mydb/feature-branch`", 328 "INSERT INTO test VALUES (3);", 329 "UPDATE test SET pk=1000 WHERE pk=0;", 330 "CALL DOLT_ADD('.');", 331 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", 332 "use `mydb/main~`", 333 }, 334 Assertions: []queries.ScriptTestAssertion{ 335 { 336 Query: "CALL DOLT_MERGE('feature-branch')", 337 ExpectedErrStr: "this operation is not supported while in a detached head state", 338 }, 339 }, 340 }, 341 { 342 Name: "CALL DOLT_MERGE no-ff correctly works with autocommit off", 343 SetUpScript: []string{ 344 "CREATE TABLE test (pk int primary key)", 345 "call DOLT_ADD('.')", 346 "INSERT INTO test VALUES (0),(1),(2);", 347 "SET autocommit = 0", 348 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", 349 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 350 "INSERT INTO test VALUES (3);", 351 "UPDATE test SET pk=1000 WHERE pk=0;", 352 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff', '--date', '2022-08-06T12:00:01');", 353 "CALL DOLT_CHECKOUT('main');", 354 }, 355 Assertions: []queries.ScriptTestAssertion{ 356 { 357 // No-FF-Merge 358 Query: "CALL DOLT_MERGE('feature-branch', '--no-ff', '-m', 'this is a no-ff')", 359 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 360 }, 361 { 362 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 363 Expected: []sql.Row{{false, nil, nil, nil}}, 364 }, 365 { 366 Query: "SELECT * from dolt_status", 367 Expected: []sql.Row{}, 368 }, 369 { 370 Query: "SELECT COUNT(*) FROM dolt_log", 371 Expected: []sql.Row{{5}}, // includes the merge commit created by no-ff and setup commits 372 }, 373 { 374 Query: "select message from dolt_log order by date DESC LIMIT 1;", 375 Expected: []sql.Row{{"this is a no-ff"}}, // includes the merge commit created by no-ff 376 }, 377 { 378 Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", 379 Expected: []sql.Row{{0, "Switched to branch 'other-branch'"}}, 380 }, 381 }, 382 }, 383 { 384 Name: "CALL DOLT_MERGE no-ff correctly works with autocommit off, no checkout", 385 SetUpScript: []string{ 386 "CREATE TABLE test (pk int primary key)", 387 "call DOLT_ADD('.')", 388 "INSERT INTO test VALUES (0),(1),(2);", 389 "SET autocommit = 0", 390 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", 391 "CALL DOLT_BRANCH('feature-branch')", 392 "USE `mydb/feature-branch`", 393 "INSERT INTO test VALUES (3);", 394 "UPDATE test SET pk=1000 WHERE pk=0;", 395 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff', '--date', '2022-08-06T12:00:01');", 396 "use `mydb/main`", 397 }, 398 Assertions: []queries.ScriptTestAssertion{ 399 { 400 // No-FF-Merge 401 Query: "CALL DOLT_MERGE('feature-branch', '--no-ff', '-m', 'this is a no-ff')", 402 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 403 }, 404 { 405 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 406 Expected: []sql.Row{{false, nil, nil, nil}}, 407 }, 408 { 409 Query: "SELECT * from dolt_status", 410 Expected: []sql.Row{}, 411 }, 412 { 413 Query: "SELECT COUNT(*) FROM dolt_log", 414 Expected: []sql.Row{{5}}, // includes the merge commit created by no-ff and setup commits 415 }, 416 { 417 Query: "select message from dolt_log order by date DESC LIMIT 1;", 418 Expected: []sql.Row{{"this is a no-ff"}}, // includes the merge commit created by no-ff 419 }, 420 { 421 Query: "select * from test order by 1", 422 Expected: []sql.Row{ 423 {1}, {2}, {3}, {1000}, 424 }, 425 }, 426 }, 427 }, 428 { 429 Name: "CALL DOLT_MERGE without conflicts correctly works with autocommit off with commit flag", 430 SetUpScript: []string{ 431 "CREATE TABLE test (pk int primary key)", 432 "CALL DOLT_ADD('.')", 433 "INSERT INTO test VALUES (0),(1),(2);", 434 "SET autocommit = 0", 435 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", 436 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 437 "INSERT INTO test VALUES (3);", 438 "UPDATE test SET pk=1000 WHERE pk=0;", 439 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", 440 "CALL DOLT_CHECKOUT('main');", 441 "INSERT INTO test VALUES (5),(6),(7);", 442 "CALL DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:03');", 443 }, 444 Assertions: []queries.ScriptTestAssertion{ 445 { 446 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge', '--commit')", 447 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 448 }, 449 { 450 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 451 Expected: []sql.Row{{false, nil, nil, nil}}, 452 }, 453 { 454 Query: "SELECT COUNT(*) from dolt_status", 455 Expected: []sql.Row{{0}}, 456 }, 457 { 458 Query: "SELECT COUNT(*) FROM dolt_log", 459 Expected: []sql.Row{{6}}, 460 }, 461 { 462 Query: "select message from dolt_log where date > '2022-08-08' order by date DESC LIMIT 1;", 463 Expected: []sql.Row{{"this is a merge"}}, 464 }, 465 }, 466 }, 467 { 468 Name: "CALL DOLT_MERGE without conflicts correctly works with autocommit off and no commit flag", 469 SetUpScript: []string{ 470 "CREATE TABLE test (pk int primary key)", 471 "CALL DOLT_ADD('.')", 472 "INSERT INTO test VALUES (0),(1),(2);", 473 "SET autocommit = 0", 474 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", 475 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 476 "INSERT INTO test VALUES (3);", 477 "UPDATE test SET pk=1000 WHERE pk=0;", 478 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", 479 "CALL DOLT_CHECKOUT('main');", 480 "INSERT INTO test VALUES (5),(6),(7);", 481 "CALL DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:03');", 482 }, 483 Assertions: []queries.ScriptTestAssertion{ 484 { 485 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge', '--no-commit')", 486 Expected: []sql.Row{{"", 0, 0, "merge successful"}}, 487 }, 488 { 489 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 490 Expected: []sql.Row{{true, "feature-branch", "refs/heads/main", ""}}, 491 }, 492 { 493 Query: "SELECT * from dolt_status", 494 Expected: []sql.Row{{"test", true, "modified"}}, 495 }, 496 { 497 Query: "SELECT COUNT(*) FROM dolt_log", 498 Expected: []sql.Row{{4}}, 499 }, 500 { 501 // careful to filter out the initial commit, which will be later than the ones above 502 Query: "select message from dolt_log where date < '2022-08-08' order by date DESC LIMIT 1;", 503 Expected: []sql.Row{{"add some more values"}}, 504 }, 505 { 506 Query: "CALL DOLT_CHECKOUT('-b', 'other')", 507 Expected: []sql.Row{{0, "Switched to branch 'other'"}}, 508 }, 509 { 510 Query: "CALL DOLT_CHECKOUT('main')", 511 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 512 }, 513 }, 514 }, 515 { 516 Name: "CALL DOLT_MERGE with conflicts can be correctly resolved when autocommit is off", 517 SetUpScript: []string{ 518 "CREATE TABLE test (pk int primary key, val int)", 519 "call DOLT_ADD('.')", 520 "INSERT INTO test VALUES (0, 0)", 521 "SET autocommit = 0", 522 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", 523 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 524 "INSERT INTO test VALUES (1, 1);", 525 "UPDATE test SET val=1000 WHERE pk=0;", 526 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", 527 "CALL DOLT_CHECKOUT('main');", 528 "UPDATE test SET val=1001 WHERE pk=0;", 529 "CALL DOLT_COMMIT('-a', '-m', 'update a value', '--date', '2022-08-06T12:00:03');", 530 }, 531 Assertions: []queries.ScriptTestAssertion{ 532 { 533 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge')", 534 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 535 }, 536 { 537 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 538 Expected: []sql.Row{{true, "feature-branch", "refs/heads/main", "test"}}, 539 }, 540 { 541 Query: "SELECT * from dolt_status", 542 Expected: []sql.Row{{"test", false, "modified"}, {"test", false, "conflict"}}, 543 }, 544 { 545 Query: "SELECT COUNT(*) FROM dolt_log", 546 Expected: []sql.Row{{4}}, 547 }, 548 { 549 Query: "select message from dolt_log where date < '2022-08-08' order by date DESC LIMIT 1;", 550 Expected: []sql.Row{{"update a value"}}, 551 }, 552 { 553 Query: "SELECT COUNT(*) FROM dolt_conflicts", 554 Expected: []sql.Row{{1}}, 555 }, 556 { 557 Query: "DELETE FROM dolt_conflicts_test", 558 Expected: []sql.Row{{types.NewOkResult(1)}}, 559 }, 560 { 561 Query: "commit", 562 Expected: []sql.Row{}, 563 }, 564 { 565 Query: "SELECT * from dolt_status", 566 Expected: []sql.Row{{"test", false, "modified"}}, 567 }, 568 { 569 Query: "SELECT * from test ORDER BY pk", 570 Expected: []sql.Row{{0, 1001}, {1, 1}}, 571 }, 572 }, 573 }, 574 { 575 // TODO: These tests are skipped, because we have temporarily disabled dolt_conflicts_resolve 576 // when there are schema conflicts, since schema conflicts prevent table data from being 577 // merged, and resolving the schema changes, but not completing the data merge will likely 578 // give customers unexpected results. 579 // https://github.com/dolthub/dolt/issues/6616 580 Name: "CALL DOLT_MERGE with schema conflicts can be correctly resolved using dolt_conflicts_resolve when autocommit is off", 581 SetUpScript: []string{ 582 "CREATE TABLE test (pk int primary key, val int)", 583 "call DOLT_ADD('.')", 584 "INSERT INTO test VALUES (0, 0)", 585 "SET autocommit = 0", 586 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", 587 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 588 "ALTER TABLE test MODIFY val bigint;", 589 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", 590 "CALL DOLT_CHECKOUT('main');", 591 "ALTER TABLE test MODIFY val smallint;", 592 "CALL DOLT_COMMIT('-a', '-m', 'update val col', '--date', '2022-08-06T12:00:03');", 593 }, 594 Assertions: []queries.ScriptTestAssertion{ 595 { 596 Skip: true, 597 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge')", 598 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 599 }, 600 { 601 Skip: true, 602 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 603 Expected: []sql.Row{{true, "feature-branch", "refs/heads/main", "test"}}, 604 }, 605 { 606 Skip: true, 607 Query: "SELECT * from dolt_status", 608 Expected: []sql.Row{{"test", false, "schema conflict"}}, 609 }, 610 { 611 Skip: true, 612 Query: "SELECT COUNT(*) FROM dolt_log", 613 Expected: []sql.Row{{4}}, 614 }, 615 { 616 Skip: true, 617 Query: "select message from dolt_log where date < '2022-08-08' order by date DESC LIMIT 1;", 618 Expected: []sql.Row{{"update val col"}}, 619 }, 620 { 621 Skip: true, 622 Query: "SELECT COUNT(*) FROM dolt_conflicts", 623 Expected: []sql.Row{{1}}, 624 }, 625 { 626 Skip: true, 627 Query: "CALL DOLT_CONFLICTS_RESOLVE('--ours', 'test');", 628 Expected: []sql.Row{{0}}, 629 }, 630 { 631 Skip: true, 632 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 633 Expected: []sql.Row{{true, "feature-branch", "refs/heads/main", ""}}, 634 }, 635 { 636 Skip: true, 637 Query: "SELECT COUNT(*) FROM dolt_conflicts", 638 Expected: []sql.Row{{0}}, 639 }, 640 { 641 Skip: true, 642 Query: "SELECT * from dolt_status", 643 Expected: []sql.Row{{"test", true, "merged"}}, 644 }, 645 { 646 Skip: true, 647 Query: "CALL DOLT_COMMIT('-m', 'merged');", 648 SkipResultsCheck: true, 649 }, 650 { 651 Skip: true, 652 Query: "SELECT * from dolt_status", 653 Expected: []sql.Row{}, 654 }, 655 { 656 Skip: true, 657 Query: "SHOW CREATE TABLE test", 658 Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `pk` int NOT NULL,\n `val` smallint,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 659 }, 660 }, 661 }, 662 { 663 Name: "merge conflicts prevent new branch creation", 664 SetUpScript: []string{ 665 "CREATE TABLE test (pk int primary key, val int)", 666 "call DOLT_ADD('.')", 667 "INSERT INTO test VALUES (0, 0)", 668 "SET autocommit = 0", 669 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", 670 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 671 "INSERT INTO test VALUES (1, 1);", 672 "UPDATE test SET val=1000 WHERE pk=0;", 673 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", 674 "CALL DOLT_CHECKOUT('main');", 675 "UPDATE test SET val=1001 WHERE pk=0;", 676 "CALL DOLT_COMMIT('-a', '-m', 'update a value', '--date', '2022-08-06T12:00:03');", 677 }, 678 Assertions: []queries.ScriptTestAssertion{ 679 { 680 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge')", 681 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 682 }, 683 { 684 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 685 Expected: []sql.Row{{true, "feature-branch", "refs/heads/main", "test"}}, 686 }, 687 { 688 Query: "SELECT * FROM DOLT_STATUS", 689 Expected: []sql.Row{{"test", false, "modified"}, {"test", false, "conflict"}}, 690 }, 691 { 692 // errors because creating a new branch implicitly commits the current transaction 693 Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", 694 ExpectedErrStr: dsess.ErrUnresolvedConflictsCommit.Error(), 695 }, 696 }, 697 }, 698 { 699 Name: "CALL DOLT_MERGE ff & squash correctly works with autocommit off", 700 SetUpScript: []string{ 701 "CREATE TABLE test (pk int primary key)", 702 "call DOLT_ADD('.')", 703 "INSERT INTO test VALUES (0),(1),(2);", 704 "SET autocommit = 0", 705 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 706 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 707 "INSERT INTO test VALUES (3);", 708 "UPDATE test SET pk=1000 WHERE pk=0;", 709 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", 710 "CALL DOLT_CHECKOUT('main');", 711 }, 712 Assertions: []queries.ScriptTestAssertion{ 713 { 714 Query: "CALL DOLT_MERGE('feature-branch', '--squash')", 715 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 716 }, 717 { 718 Query: "SELECT count(*) from dolt_status", 719 Expected: []sql.Row{{1}}, 720 }, 721 { 722 Query: "SELECT COUNT(*) FROM dolt_log", 723 Expected: []sql.Row{{3}}, 724 }, 725 { 726 Query: "SELECT * FROM test order by pk", 727 Expected: []sql.Row{{1}, {2}, {3}, {1000}}, 728 }, 729 }, 730 }, 731 { 732 Name: "CALL DOLT_MERGE ff & squash with a checkout in between", 733 SetUpScript: []string{ 734 "CREATE TABLE test (pk int primary key)", 735 "call DOLT_ADD('.')", 736 "INSERT INTO test VALUES (0),(1),(2);", 737 "SET autocommit = 0", 738 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 739 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 740 "INSERT INTO test VALUES (3);", 741 "UPDATE test SET pk=1000 WHERE pk=0;", 742 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", 743 "CALL DOLT_CHECKOUT('main');", 744 }, 745 Assertions: []queries.ScriptTestAssertion{ 746 { 747 Query: "CALL DOLT_MERGE('feature-branch', '--squash')", 748 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 749 }, 750 { 751 Query: "CALL DOLT_CHECKOUT('-b', 'other')", 752 Expected: []sql.Row{{0, "Switched to branch 'other'"}}, 753 }, 754 { 755 Query: "CALL DOLT_CHECKOUT('main')", 756 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 757 }, 758 { 759 Query: "SELECT * FROM test order by pk", 760 Expected: []sql.Row{{1}, {2}, {3}, {1000}}, 761 }, 762 }, 763 }, 764 { 765 Name: "CALL DOLT_MERGE ff", 766 SetUpScript: []string{ 767 "CREATE TABLE test (pk int primary key)", 768 "CALL DOLT_ADD('.')", 769 "INSERT INTO test VALUES (0),(1),(2);", 770 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 771 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 772 "INSERT INTO test VALUES (3);", 773 "UPDATE test SET pk=1000 WHERE pk=0;", 774 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", 775 "CALL DOLT_CHECKOUT('main');", 776 }, 777 Assertions: []queries.ScriptTestAssertion{ 778 { 779 // FF-Merge 780 Query: "CALL DOLT_MERGE('feature-branch')", 781 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 782 }, 783 { 784 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 785 Expected: []sql.Row{{false, nil, nil, nil}}, 786 }, 787 { 788 Query: "SELECT * from dolt_status", 789 Expected: []sql.Row{}, 790 }, 791 { 792 Query: "CALL DOLT_CHECKOUT('-b', 'new-branch')", 793 Expected: []sql.Row{{0, "Switched to branch 'new-branch'"}}, 794 }, 795 { 796 Query: "INSERT INTO test VALUES (4)", 797 Expected: []sql.Row{{types.NewOkResult(1)}}, 798 }, 799 }, 800 }, 801 { 802 Name: "CALL DOLT_MERGE ff no checkout", 803 SetUpScript: []string{ 804 "CREATE TABLE test (pk int primary key)", 805 "CALL DOLT_ADD('.')", 806 "INSERT INTO test VALUES (0),(1),(2);", 807 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 808 "CALL dolt_branch('feature-branch')", 809 "use `mydb/feature-branch`", 810 "INSERT INTO test VALUES (3);", 811 "UPDATE test SET pk=1000 WHERE pk=0;", 812 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", 813 "use mydb/main;", 814 }, 815 Assertions: []queries.ScriptTestAssertion{ 816 { 817 // FF-Merge 818 Query: "CALL DOLT_MERGE('feature-branch')", 819 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 820 }, 821 { 822 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 823 Expected: []sql.Row{{false, nil, nil, nil}}, 824 }, 825 { 826 Query: "SELECT * from dolt_status", 827 Expected: []sql.Row{}, 828 }, 829 { 830 Query: "CALL DOLT_CHECKOUT('-b', 'new-branch')", 831 Expected: []sql.Row{{0, "Switched to branch 'new-branch'"}}, 832 }, 833 { 834 Query: "select active_branch()", 835 Expected: []sql.Row{{"new-branch"}}, 836 }, 837 { 838 Query: "INSERT INTO test VALUES (4)", 839 Expected: []sql.Row{{types.NewOkResult(1)}}, 840 }, 841 { 842 Query: "SELECT * FROM test order by pk", 843 Expected: []sql.Row{{1}, {2}, {3}, {4}, {1000}}, 844 }, 845 { 846 Query: "use `mydb/main`", 847 SkipResultsCheck: true, 848 }, 849 { 850 Query: "select active_branch()", 851 Expected: []sql.Row{{"main"}}, 852 }, 853 { 854 Query: "SELECT * FROM test order by pk", 855 Expected: []sql.Row{{1}, {2}, {3}, {1000}}, 856 }, 857 }, 858 }, 859 { 860 Name: "CALL DOLT_MERGE no-ff", 861 SetUpScript: []string{ 862 "CREATE TABLE test (pk int primary key)", 863 "CALL DOLT_ADD('.')", 864 "INSERT INTO test VALUES (0),(1),(2);", 865 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 866 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 867 "INSERT INTO test VALUES (3);", 868 "UPDATE test SET pk=1000 WHERE pk=0;", 869 "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", 870 "CALL DOLT_CHECKOUT('main');", 871 }, 872 Assertions: []queries.ScriptTestAssertion{ 873 { 874 // No-FF-Merge 875 Query: "CALL DOLT_MERGE('feature-branch', '-no-ff', '-m', 'this is a no-ff')", 876 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 877 }, 878 { 879 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 880 Expected: []sql.Row{{false, nil, nil, nil}}, 881 }, 882 { 883 Query: "SELECT * from dolt_status", 884 Expected: []sql.Row{}, 885 }, 886 { 887 Query: "SELECT COUNT(*) FROM dolt_log", 888 Expected: []sql.Row{{5}}, // includes the merge commit created by no-ff and setup commits 889 }, 890 { 891 Query: "select message from dolt_log order by date DESC LIMIT 1;", 892 Expected: []sql.Row{{"this is a no-ff"}}, // includes the merge commit created by no-ff 893 }, 894 { 895 Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", 896 Expected: []sql.Row{{0, "Switched to branch 'other-branch'"}}, 897 }, 898 }, 899 }, 900 { 901 Name: "CALL DOLT_MERGE with no conflicts works", 902 SetUpScript: []string{ 903 "CREATE TABLE test (pk int primary key)", 904 "CALL DOLT_ADD('.')", 905 "INSERT INTO test VALUES (0),(1),(2);", 906 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", 907 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 908 "INSERT INTO test VALUES (3);", 909 "UPDATE test SET pk=1000 WHERE pk=0;", 910 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:01');", 911 "CALL DOLT_CHECKOUT('main');", 912 "INSERT INTO test VALUES (5),(6),(7);", 913 "CALL DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:02');", 914 }, 915 Assertions: []queries.ScriptTestAssertion{ 916 { 917 Query: "CALL DOLT_MERGE('feature-branch', '--no-commit', '--commit')", 918 ExpectedErrStr: "cannot define both 'commit' and 'no-commit' flags at the same time", 919 }, 920 { 921 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge')", 922 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 923 }, 924 { 925 Query: "SELECT COUNT(*) from dolt_status", 926 Expected: []sql.Row{{0}}, 927 }, 928 { 929 Query: "SELECT COUNT(*) FROM dolt_log", 930 Expected: []sql.Row{{6}}, // includes the merge commit and a new commit created by successful merge 931 }, 932 { 933 Query: "select message from dolt_log where date > '2022-08-08' order by date DESC LIMIT 1;", 934 Expected: []sql.Row{{"this is a merge"}}, 935 }, 936 }, 937 }, 938 { 939 Name: "CALL DOLT_MERGE with no conflicts works, no checkout", 940 SetUpScript: []string{ 941 "CREATE TABLE test (pk int primary key)", 942 "CALL DOLT_ADD('.')", 943 "INSERT INTO test VALUES (0),(1),(2);", 944 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", 945 "CALL dolt_branch('feature-branch')", 946 "use `mydb/feature-branch`", 947 "INSERT INTO test VALUES (3);", 948 "UPDATE test SET pk=1000 WHERE pk=0;", 949 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:01');", 950 "use mydb/main", 951 "INSERT INTO test VALUES (5),(6),(7);", 952 "CALL DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:02');", 953 }, 954 Assertions: []queries.ScriptTestAssertion{ 955 { 956 Query: "CALL DOLT_MERGE('feature-branch', '--no-commit', '--commit')", 957 ExpectedErrStr: "cannot define both 'commit' and 'no-commit' flags at the same time", 958 }, 959 { 960 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge')", 961 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 962 }, 963 { 964 Query: "SELECT COUNT(*) from dolt_status", 965 Expected: []sql.Row{{0}}, 966 }, 967 { 968 Query: "SELECT COUNT(*) FROM dolt_log", 969 Expected: []sql.Row{{6}}, // includes the merge commit and a new commit created by successful merge 970 }, 971 { 972 Query: "select message from dolt_log where date > '2022-08-08' order by date DESC LIMIT 1;", 973 Expected: []sql.Row{{"this is a merge"}}, 974 }, 975 { 976 Query: "select * from test order by pk", 977 Expected: []sql.Row{ 978 {1}, {2}, {3}, {5}, {6}, {7}, {1000}, 979 }, 980 }, 981 { 982 Query: "use `mydb/feature-branch`", 983 SkipResultsCheck: true, 984 }, 985 { 986 Query: "select * from test order by pk", 987 Expected: []sql.Row{ 988 {1}, {2}, {3}, {1000}, 989 }, 990 }, 991 }, 992 }, 993 { 994 Name: "CALL DOLT_MERGE with no conflicts works with no-commit flag", 995 SetUpScript: []string{ 996 "CREATE TABLE test (pk int primary key)", 997 "CALL DOLT_ADD('.')", 998 "INSERT INTO test VALUES (0),(1),(2);", 999 "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", 1000 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 1001 "INSERT INTO test VALUES (3);", 1002 "UPDATE test SET pk=1000 WHERE pk=0;", 1003 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:01');", 1004 "CALL DOLT_CHECKOUT('main');", 1005 "INSERT INTO test VALUES (5),(6),(7);", 1006 "CALL DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:02');", 1007 }, 1008 Assertions: []queries.ScriptTestAssertion{ 1009 { 1010 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge', '--no-commit')", 1011 Expected: []sql.Row{{"", 0, 0, "merge successful"}}, 1012 }, 1013 { 1014 Query: "SELECT COUNT(*) from dolt_status", 1015 Expected: []sql.Row{{1}}, 1016 }, 1017 { 1018 Query: "SELECT COUNT(*) FROM dolt_log", 1019 Expected: []sql.Row{{4}}, 1020 }, 1021 { 1022 Query: "select message from dolt_log where date < '2022-08-08' order by date DESC LIMIT 1;", 1023 Expected: []sql.Row{{"add some more values"}}, 1024 }, 1025 { 1026 Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", 1027 Expected: []sql.Row{{0, "Switched to branch 'other-branch'"}}, 1028 }, 1029 }, 1030 }, 1031 { 1032 Name: "CALL DOLT_MERGE when current or ahead results in a no-op", 1033 SetUpScript: []string{ 1034 "CREATE TABLE test (pk int primary key)", 1035 "CALL DOLT_ADD('.')", 1036 "CALL DOLT_COMMIT('-A', '-m', 'commit');", 1037 }, 1038 Assertions: []queries.ScriptTestAssertion{ 1039 { 1040 Query: "CALL DOLT_MERGE('HEAD~1')", 1041 Expected: []sql.Row{{"", 0, 0, "cannot fast forward from a to b. a is ahead of b already"}}, 1042 }, 1043 { 1044 Query: "CALL DOLT_MERGE('HEAD')", 1045 Expected: []sql.Row{{"", 0, 0, "Everything up-to-date"}}, 1046 }, 1047 }, 1048 }, 1049 { 1050 Name: "CALL DOLT_MERGE with conflict is queryable and committable with dolt_allow_commit_conflicts on", 1051 SetUpScript: []string{ 1052 "CREATE TABLE test (pk int primary key, val int)", 1053 "CALL DOLT_ADD('.')", 1054 "INSERT INTO test VALUES (0, 0)", 1055 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 1056 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 1057 "INSERT INTO test VALUES (1, 1);", 1058 "UPDATE test SET val=1000 WHERE pk=0;", 1059 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit');", 1060 "CALL DOLT_CHECKOUT('main');", 1061 "UPDATE test SET val=1001 WHERE pk=0;", 1062 "CALL DOLT_COMMIT('-a', '-m', 'update a value');", 1063 "set dolt_allow_commit_conflicts = on", 1064 }, 1065 Assertions: []queries.ScriptTestAssertion{ 1066 { 1067 Query: "CALL DOLT_MERGE('feature-branch')", 1068 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 1069 }, 1070 { 1071 Query: "SELECT count(*) from dolt_conflicts_test", 1072 Expected: []sql.Row{{1}}, 1073 }, 1074 { 1075 Query: "CALL DOLT_MERGE('--abort')", 1076 Expected: []sql.Row{{"", 0, 0, "merge aborted"}}, 1077 }, 1078 { 1079 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 1080 Expected: []sql.Row{{false, nil, nil, nil}}, 1081 }, 1082 { 1083 Query: "SELECT * FROM test", 1084 Expected: []sql.Row{{0, 1001}}, 1085 }, 1086 { 1087 Query: "SELECT count(*) from dolt_conflicts_test", 1088 Expected: []sql.Row{{0}}, 1089 }, 1090 { 1091 Query: "SELECT count(*) from dolt_status", 1092 Expected: []sql.Row{{0}}, 1093 }, 1094 { 1095 Query: "SET dolt_allow_commit_conflicts = 0", 1096 Expected: []sql.Row{{}}, 1097 }, 1098 { 1099 Query: "CALL DOLT_MERGE('feature-branch')", 1100 ExpectedErrStr: dsess.ErrUnresolvedConflictsAutoCommit.Error(), 1101 }, 1102 { 1103 Query: "SELECT count(*) from dolt_conflicts_test", // transaction has been rolled back, 0 results 1104 Expected: []sql.Row{{0}}, 1105 }, 1106 }, 1107 }, 1108 { 1109 Name: "CALL DOLT_MERGE with conflicts can be aborted when autocommit is off", 1110 SetUpScript: []string{ 1111 "CREATE TABLE test (pk int primary key, val int)", 1112 "CALL DOLT_ADD('.')", 1113 "INSERT INTO test VALUES (0, 0)", 1114 "SET autocommit = 0", 1115 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 1116 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 1117 "INSERT INTO test VALUES (1, 1);", 1118 "UPDATE test SET val=1000 WHERE pk=0;", 1119 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit');", 1120 "CALL DOLT_CHECKOUT('main');", 1121 "UPDATE test SET val=1001 WHERE pk=0;", 1122 "CALL DOLT_COMMIT('-a', '-m', 'update a value');", 1123 }, 1124 Assertions: []queries.ScriptTestAssertion{ 1125 { 1126 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge')", 1127 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 1128 }, 1129 { 1130 Query: "SELECT * from dolt_status", 1131 Expected: []sql.Row{{"test", false, "modified"}, {"test", false, "conflict"}}, 1132 }, 1133 { 1134 Query: "SELECT COUNT(*) FROM dolt_conflicts", 1135 Expected: []sql.Row{{1}}, 1136 }, 1137 { 1138 Query: "CALL DOLT_MERGE('--abort')", 1139 Expected: []sql.Row{{"", 0, 0, "merge aborted"}}, 1140 }, 1141 { 1142 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 1143 Expected: []sql.Row{{false, nil, nil, nil}}, 1144 }, 1145 { 1146 Query: "SELECT * from dolt_status", 1147 Expected: []sql.Row{}, 1148 }, 1149 { 1150 Query: "SELECT COUNT(*) FROM dolt_log", 1151 Expected: []sql.Row{{4}}, 1152 }, 1153 { 1154 Query: "SELECT * FROM test ORDER BY pk", 1155 Expected: []sql.Row{{0, 1001}}, 1156 }, 1157 { 1158 Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", 1159 Expected: []sql.Row{{0, "Switched to branch 'other-branch'"}}, 1160 }, 1161 }, 1162 }, 1163 { 1164 Name: "DOLT_MERGE(--abort) clears staged", 1165 SetUpScript: []string{ 1166 "CREATE TABLE test (pk int primary key);", 1167 "INSERT INTO test VALUES (0),(1),(2);", 1168 "set autocommit = off;", 1169 "CREATE TABLE one_pk (pk1 BIGINT NOT NULL, c1 BIGINT, c2 BIGINT, PRIMARY KEY (pk1));", 1170 "CALL DOLT_ADD('.');", 1171 "call dolt_commit('-a', '-m', 'add tables');", 1172 "call dolt_checkout('-b', 'feature-branch');", 1173 "call dolt_checkout('main');", 1174 "INSERT INTO one_pk (pk1,c1,c2) VALUES (0,0,0);", 1175 "call dolt_commit('-a', '-m', 'changed main');", 1176 "call dolt_checkout('feature-branch');", 1177 "INSERT INTO one_pk (pk1,c1,c2) VALUES (0,1,1);", 1178 "call dolt_commit('-a', '-m', 'changed feature branch');", 1179 "call dolt_checkout('main');", 1180 "call dolt_merge('feature-branch');", 1181 "call dolt_merge('--abort');", 1182 }, 1183 Assertions: []queries.ScriptTestAssertion{ 1184 { 1185 Query: "select * from dolt_status;", 1186 Expected: []sql.Row{}, 1187 }, 1188 }, 1189 }, 1190 { 1191 Name: "CALL DOLT_MERGE complains when a merge overrides local changes", 1192 SetUpScript: []string{ 1193 "CREATE TABLE test (pk int primary key, val int)", 1194 "CALL DOLT_ADD('.')", 1195 "INSERT INTO test VALUES (0, 0)", 1196 "SET autocommit = 0", 1197 "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", 1198 "CALL DOLT_CHECKOUT('-b', 'feature-branch')", 1199 "INSERT INTO test VALUES (1, 1);", 1200 "UPDATE test SET val=1000 WHERE pk=0;", 1201 "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit');", 1202 "CALL DOLT_CHECKOUT('main');", 1203 "UPDATE test SET val=1001 WHERE pk=0;", 1204 }, 1205 Assertions: []queries.ScriptTestAssertion{ 1206 { 1207 Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge')", 1208 ExpectedErrStr: "error: local changes would be stomped by merge:\n\ttest\n Please commit your changes before you merge.", 1209 }, 1210 { 1211 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 1212 Expected: []sql.Row{{false, nil, nil, nil}}, 1213 }, 1214 }, 1215 }, 1216 { 1217 Name: "Drop and add primary key on two branches converges to same schema", 1218 SetUpScript: []string{ 1219 "create table t1 (i int);", 1220 "call dolt_add('.');", 1221 "call dolt_commit('-am', 't1 table')", 1222 "call dolt_checkout('-b', 'b1')", 1223 "alter table t1 add primary key(i)", 1224 "alter table t1 drop primary key", 1225 "alter table t1 add primary key(i)", 1226 "alter table t1 drop primary key", 1227 "alter table t1 add primary key(i)", 1228 "call dolt_commit('-am', 'b1 primary key changes')", 1229 "call dolt_checkout('main')", 1230 "alter table t1 add primary key(i)", 1231 "call dolt_commit('-am', 'main primary key change')", 1232 }, 1233 Assertions: []queries.ScriptTestAssertion{ 1234 { 1235 Query: "call dolt_merge('b1')", 1236 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1237 }, 1238 { 1239 Query: "select count(*) from dolt_conflicts", 1240 Expected: []sql.Row{{0}}, 1241 }, 1242 }, 1243 }, 1244 { 1245 Name: "Constraint violations are persisted", 1246 SetUpScript: []string{ 1247 "set dolt_force_transaction_commit = on;", 1248 "CREATE table parent (pk int PRIMARY KEY, col1 int);", 1249 "CREATE table child (pk int PRIMARY KEY, parent_fk int, FOREIGN KEY (parent_fk) REFERENCES parent(pk));", 1250 "CREATE table other (pk int);", 1251 "CALL DOLT_ADD('.')", 1252 "INSERT INTO parent VALUES (1, 1), (2, 2);", 1253 "CALL DOLT_COMMIT('-am', 'setup');", 1254 "CALL DOLT_BRANCH('branch1');", 1255 "CALL DOLT_BRANCH('branch2');", 1256 "DELETE FROM parent where pk = 1;", 1257 "CALL DOLT_COMMIT('-am', 'delete parent 1');", 1258 "CALL DOLT_CHECKOUT('branch1');", 1259 "INSERT INTO CHILD VALUES (1, 1);", 1260 "CALL DOLT_COMMIT('-am', 'insert child of parent 1');", 1261 "CALL DOLT_CHECKOUT('main');", 1262 }, 1263 Assertions: []queries.ScriptTestAssertion{ 1264 { 1265 Query: "CALL DOLT_MERGE('branch1');", 1266 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 1267 }, 1268 { 1269 Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;", 1270 Expected: []sql.Row{{"foreign key", 1, 1}}, 1271 }, 1272 }, 1273 }, 1274 { 1275 // from constraint-violations.bats 1276 Name: "ancestor contains fk, main parent remove with backup, other child add, restrict", 1277 SetUpScript: []string{ 1278 "CREATE TABLE parent (pk BIGINT PRIMARY KEY, v1 BIGINT, INDEX(v1));", 1279 "CREATE TABLE child (pk BIGINT PRIMARY KEY, v1 BIGINT, CONSTRAINT fk_name FOREIGN KEY (v1) REFERENCES parent (v1));", 1280 "CALL DOLT_ADD('.')", 1281 "INSERT INTO parent VALUES (10, 1), (20, 2), (30, 2);", 1282 "INSERT INTO child VALUES (1, 1);", 1283 "CALL DOLT_COMMIT('-am', 'MC1');", 1284 "CALL DOLT_BRANCH('other');", 1285 "DELETE from parent WHERE pk = 20;", 1286 "CALL DOLT_COMMIT('-am', 'MC2');", 1287 1288 "CALL DOLT_CHECKOUT('other');", 1289 "INSERT INTO child VALUES (2, 2);", 1290 "CALL DOLT_COMMIT('-am', 'OC1');", 1291 "CALL DOLT_CHECKOUT('main');", 1292 "set DOLT_FORCE_TRANSACTION_COMMIT = on;", 1293 "CALL DOLT_MERGE('other');", 1294 }, 1295 Assertions: []queries.ScriptTestAssertion{ 1296 { 1297 Query: "SELECT * from dolt_constraint_violations", 1298 Expected: []sql.Row{}, 1299 }, 1300 { 1301 Query: "SELECT * from dolt_constraint_violations_parent", 1302 Expected: []sql.Row{}, 1303 }, 1304 { 1305 Query: "SELECT * from dolt_constraint_violations_child", 1306 Expected: []sql.Row{}, 1307 }, 1308 { 1309 Query: "SELECT * from parent;", 1310 Expected: []sql.Row{{10, 1}, {30, 2}}, 1311 }, 1312 { 1313 Query: "SELECT * from child;", 1314 Expected: []sql.Row{{1, 1}, {2, 2}}, 1315 }, 1316 }, 1317 }, 1318 // unique indexes 1319 { 1320 Name: "unique keys, insert violation", 1321 SetUpScript: []string{ 1322 "SET dolt_force_transaction_commit = on;", 1323 "CREATE TABLE t (pk int PRIMARY KEY, col1 int UNIQUE);", 1324 "CALL dolt_add('.')", 1325 "CALL DOLT_COMMIT('-am', 'create table');", 1326 1327 "CALL DOLT_CHECKOUT('-b', 'right');", 1328 "INSERT INTO t VALUES (2, 1), (3, 3);", 1329 "CALL DOLT_COMMIT('-am', 'right insert');", 1330 1331 "CALL DOLT_CHECKOUT('main');", 1332 "INSERT INTO t values (1, 1), (4, 4);", 1333 "CALL DOLT_COMMIT('-am', 'left insert');", 1334 }, 1335 Assertions: []queries.ScriptTestAssertion{ 1336 { 1337 Query: "CALL DOLT_MERGE('right');", 1338 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 1339 }, 1340 { 1341 Query: "SELECT * from t;", 1342 Expected: []sql.Row{{1, 1}, {2, 1}, {3, 3}, {4, 4}}, 1343 }, 1344 { 1345 Query: "SELECT violation_type, pk, col1 from dolt_constraint_violations_t;", 1346 Expected: []sql.Row{{"unique index", 1, 1}, {"unique index", 2, 1}}, 1347 }, 1348 { 1349 Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", 1350 Expected: []sql.Row{{true, "right", "refs/heads/main", "t"}}, 1351 }, 1352 }, 1353 }, 1354 { 1355 Name: "unique keys, update violation from left", 1356 SetUpScript: []string{ 1357 "SET dolt_force_transaction_commit = on;", 1358 "CREATE TABLE t (pk int PRIMARY KEY, col1 int UNIQUE);", 1359 "CALL DOLT_ADD('.')", 1360 "INSERT INTO t VALUES (1, 1), (2, 2);", 1361 "CALL DOLT_COMMIT('-am', 'create table');", 1362 1363 "CALL DOLT_CHECKOUT('-b', 'right');", 1364 "INSERT INTO t values (3, 3);", 1365 "CALL DOLT_COMMIT('-am', 'right insert');", 1366 1367 "CALL DOLT_CHECKOUT('main');", 1368 "UPDATE t SET col1 = 3 where pk = 2;", 1369 "CALL DOLT_COMMIT('-am', 'left insert');", 1370 }, 1371 Assertions: []queries.ScriptTestAssertion{ 1372 { 1373 Query: "CALL DOLT_MERGE('right');", 1374 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 1375 }, 1376 { 1377 Query: "SELECT * from t;", 1378 Expected: []sql.Row{{1, 1}, {2, 3}, {3, 3}}, 1379 }, 1380 { 1381 Query: "SELECT violation_type, pk, col1 from dolt_constraint_violations_t;", 1382 Expected: []sql.Row{{"unique index", 2, 3}, {"unique index", 3, 3}}, 1383 }, 1384 }, 1385 }, 1386 { 1387 Name: "unique keys, update violation from right", 1388 SetUpScript: []string{ 1389 "SET dolt_force_transaction_commit = on;", 1390 "CREATE TABLE t (pk int PRIMARY KEY, col1 int UNIQUE);", 1391 "CALL DOLT_ADD('.')", 1392 "INSERT INTO t VALUES (1, 1), (2, 2);", 1393 "CALL DOLT_COMMIT('-am', 'create table');", 1394 1395 "CALL DOLT_CHECKOUT('-b', 'right');", 1396 "UPDATE t SET col1 = 3 where pk = 2;", 1397 "CALL DOLT_COMMIT('-am', 'right insert');", 1398 1399 "CALL DOLT_CHECKOUT('main');", 1400 "INSERT INTO t values (3, 3);", 1401 "CALL DOLT_COMMIT('-am', 'left insert');", 1402 }, 1403 Assertions: []queries.ScriptTestAssertion{ 1404 { 1405 Query: "CALL DOLT_MERGE('right');", 1406 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 1407 }, 1408 { 1409 Query: "SELECT * from t;", 1410 Expected: []sql.Row{{1, 1}, {2, 3}, {3, 3}}, 1411 }, 1412 { 1413 Query: "SELECT violation_type, pk, col1 from dolt_constraint_violations_t;", 1414 Expected: []sql.Row{{"unique index", 2, 3}, {"unique index", 3, 3}}, 1415 }, 1416 }, 1417 }, 1418 { 1419 Name: "cell-wise merges can result in a unique key violation", 1420 SetUpScript: []string{ 1421 "SET dolt_force_transaction_commit = on;", 1422 "CREATE TABLE t (pk int PRIMARY KEY, col1 int, col2 int, UNIQUE col1_col2_u (col1, col2));", 1423 "CALL DOLT_ADD('.')", 1424 "INSERT INTO T VALUES (1, 1, 1), (2, NULL, NULL);", 1425 "CALL DOLT_COMMIT('-am', 'setup');", 1426 1427 "CALL DOLT_CHECKOUT('-b', 'right');", 1428 "UPDATE t SET col2 = 1 where pk = 2;", 1429 "CALL DOLT_COMMIT('-am', 'right edit');", 1430 1431 "CALL DOLT_CHECKOUT('main');", 1432 "UPDATE t SET col1 = 1 where pk = 2;", 1433 "CALL DOLT_COMMIT('-am', 'left edit');", 1434 }, 1435 Assertions: []queries.ScriptTestAssertion{ 1436 { 1437 Query: "CALL DOLT_MERGE('right');", 1438 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 1439 }, 1440 { 1441 Query: "SELECT * from t;", 1442 Expected: []sql.Row{{1, 1, 1}, {2, 1, 1}}, 1443 }, 1444 { 1445 Query: "SELECT violation_type, pk, col1, col2 from dolt_constraint_violations_t;", 1446 Expected: []sql.Row{{"unique index", 1, 1, 1}, {"unique index", 2, 1, 1}}, 1447 }, 1448 }, 1449 }, 1450 // Behavior between new and old format diverges in the case where right adds 1451 // a unique key constraint and resolves existing violations. 1452 // In the old format, because the violations exist on the left the merge is aborted. 1453 // In the new format, the merge can be completed successfully without error. 1454 // See MergeArtifactScripts and OldFormatMergeConflictsAndCVsScripts 1455 { 1456 Name: "left adds a unique key constraint and resolves existing violations", 1457 SetUpScript: []string{ 1458 "SET dolt_force_transaction_commit = on;", 1459 "CREATE TABLE t (pk int PRIMARY KEY, col1 int);", 1460 "CALL DOLT_ADD('.')", 1461 "INSERT INTO t VALUES (1, 1), (2, 1);", 1462 "CALL DOLT_COMMIT('-am', 'table and data');", 1463 1464 "CALL DOLT_CHECKOUT('-b', 'right');", 1465 "INSERT INTO t VALUES (3, 3);", 1466 "CALL DOLT_COMMIT('-am', 'right edit');", 1467 1468 "CALL DOLT_CHECKOUT('main');", 1469 "UPDATE t SET col1 = 2 where pk = 2;", 1470 "ALTER TABLE t ADD UNIQUE col1_uniq (col1);", 1471 "CALL DOLT_COMMIT('-am', 'left adds a unique index');", 1472 }, 1473 Assertions: []queries.ScriptTestAssertion{ 1474 { 1475 Query: "CALL DOLT_MERGE('right');", 1476 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1477 }, 1478 { 1479 Query: "SELECT * from t;", 1480 Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, 1481 }, 1482 }, 1483 }, 1484 { 1485 Name: "insert two tables with the same name and different schema", 1486 SetUpScript: []string{ 1487 "SET dolt_allow_commit_conflicts = on;", 1488 "CALL DOLT_CHECKOUT('-b', 'other');", 1489 "CREATE TABLE t (pk int PRIMARY key, col1 int, extracol int);", 1490 "CALL DOLT_ADD('.')", 1491 "INSERT into t VALUES (1, 1, 1);", 1492 "CALL DOLT_COMMIT('-am', 'right');", 1493 1494 "CALL DOLT_CHECKOUT('main');", 1495 "CREATE TABLE t (pk int PRIMARY key, col1 int);", 1496 "CALL DOLT_ADD('.')", 1497 "INSERT into t VALUES (2, 2);", 1498 "CALL DOLT_COMMIT('-am', 'left');", 1499 }, 1500 Assertions: []queries.ScriptTestAssertion{ 1501 { 1502 Query: "CALL DOLT_MERGE('other');", 1503 ExpectedErrStr: "table with same name 't' added in 2 commits can't be merged", 1504 }, 1505 }, 1506 }, 1507 { 1508 Name: "insert two tables with the same name and schema that don't conflict", 1509 SetUpScript: []string{ 1510 "SET dolt_allow_commit_conflicts = on;", 1511 "CALL DOLT_CHECKOUT('-b', 'other');", 1512 "CREATE TABLE t (pk int PRIMARY key, col1 int);", 1513 "CALL DOLT_ADD('.')", 1514 "INSERT into t VALUES (1, 1);", 1515 "CALL DOLT_COMMIT('-am', 'right');", 1516 1517 "CALL DOLT_CHECKOUT('main');", 1518 "CREATE TABLE t (pk int PRIMARY key, col1 int);", 1519 "CALL DOLT_ADD('.')", 1520 "INSERT into t VALUES (2, 2);", 1521 "CALL DOLT_COMMIT('-am', 'left');", 1522 }, 1523 Assertions: []queries.ScriptTestAssertion{ 1524 { 1525 Query: "CALL DOLT_MERGE('other');", 1526 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1527 }, 1528 { 1529 Query: "SELECT * from t;", 1530 Expected: []sql.Row{{1, 1}, {2, 2}}, 1531 }, 1532 }, 1533 }, 1534 { 1535 Name: "insert two tables with the same name and schema that conflict", 1536 SetUpScript: []string{ 1537 "SET dolt_allow_commit_conflicts = on;", 1538 "CALL DOLT_CHECKOUT('-b', 'other');", 1539 "CREATE TABLE t (pk int PRIMARY key, col1 int);", 1540 "CALL DOLT_ADD('.')", 1541 "INSERT into t VALUES (1, -1);", 1542 "CALL DOLT_COMMIT('-am', 'right');", 1543 1544 "CALL DOLT_CHECKOUT('main');", 1545 "CREATE TABLE t (pk int PRIMARY key, col1 int);", 1546 "CALL DOLT_ADD('.')", 1547 "INSERT into t VALUES (1, 1);", 1548 "CALL DOLT_COMMIT('-am', 'left');", 1549 }, 1550 Assertions: []queries.ScriptTestAssertion{ 1551 { 1552 Query: "CALL DOLT_MERGE('other');", 1553 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 1554 }, 1555 { 1556 Query: "SELECT base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 1557 Expected: []sql.Row{{nil, nil, 1, 1, 1, -1}}, 1558 }, 1559 { 1560 Query: "SELECT * from t;", 1561 Expected: []sql.Row{{1, 1}}, 1562 }, 1563 }, 1564 }, 1565 { 1566 Name: "merge with new triggers defined", 1567 SetUpScript: []string{ 1568 "SET dolt_allow_commit_conflicts = on;", 1569 // create table and trigger1 (main & other) 1570 "CREATE TABLE x(a BIGINT PRIMARY KEY)", 1571 "CREATE TRIGGER trigger1 BEFORE INSERT ON x FOR EACH ROW SET new.a = new.a + 1", 1572 "CALL dolt_add('-A')", 1573 "CALL dolt_commit('-m', 'added table with trigger')", 1574 "CALL dolt_branch('-c', 'main', 'other')", 1575 // create trigger2 on main 1576 "CREATE TRIGGER trigger2 BEFORE INSERT ON x FOR EACH ROW SET new.a = (new.a * 2) + 10", 1577 "CALL dolt_commit('-am', 'created trigger2 on main')", 1578 // create trigger3 & trigger4 on other 1579 "CALL dolt_checkout('other')", 1580 "CREATE TRIGGER trigger3 BEFORE INSERT ON x FOR EACH ROW SET new.a = (new.a * 2) + 100", 1581 "CREATE TRIGGER trigger4 BEFORE INSERT ON x FOR EACH ROW SET new.a = (new.a * 2) + 1000", 1582 "CALL dolt_commit('-am', 'created triggers 3 & 4 on other');", 1583 "CALL dolt_checkout('main');", 1584 }, 1585 Assertions: []queries.ScriptTestAssertion{ 1586 { 1587 Query: "CALL DOLT_MERGE('other');", 1588 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1589 }, 1590 { 1591 Query: "select count(*) from dolt_schemas where type = 'trigger';", 1592 Expected: []sql.Row{{4}}, 1593 }, 1594 }, 1595 }, 1596 { 1597 Name: "dolt_merge() works with no auto increment overlap", 1598 SetUpScript: []string{ 1599 "CREATE TABLE t (pk int PRIMARY KEY AUTO_INCREMENT, c0 int);", 1600 "CALL DOLT_ADD('.')", 1601 "INSERT INTO t (c0) VALUES (1), (2);", 1602 "CALL dolt_commit('-a', '-m', 'cm1');", 1603 "CALL dolt_checkout('-b', 'test');", 1604 "INSERT INTO t (c0) VALUES (3), (4);", 1605 "CALL dolt_commit('-a', '-m', 'cm2');", 1606 "CALL dolt_checkout('main');", 1607 }, 1608 Assertions: []queries.ScriptTestAssertion{ 1609 { 1610 Query: "CALL dolt_merge('test');", 1611 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 1612 }, 1613 { 1614 Query: "INSERT INTO t VALUES (NULL,5),(6,6),(NULL,7);", 1615 Expected: []sql.Row{{types.OkResult{RowsAffected: 3, InsertID: 5}}}, 1616 }, 1617 { 1618 Query: "SELECT * FROM t ORDER BY pk;", 1619 Expected: []sql.Row{ 1620 {1, 1}, 1621 {2, 2}, 1622 {3, 3}, 1623 {4, 4}, 1624 {5, 5}, 1625 {6, 6}, 1626 {7, 7}, 1627 }, 1628 }, 1629 }, 1630 }, 1631 { 1632 Name: "dolt_merge() (3way) works with no auto increment overlap", 1633 SetUpScript: []string{ 1634 "CREATE TABLE t (pk int PRIMARY KEY AUTO_INCREMENT, c0 int);", 1635 "CALL DOLT_ADD('.')", 1636 "INSERT INTO t (c0) VALUES (1);", 1637 "CALL dolt_commit('-a', '-m', 'cm1');", 1638 "CALL dolt_checkout('-b', 'test');", 1639 "INSERT INTO t (pk,c0) VALUES (3,3), (4,4);", 1640 "CALL dolt_commit('-a', '-m', 'cm2');", 1641 "CALL dolt_checkout('main');", 1642 "INSERT INTO t (c0) VALUES (5);", 1643 "CALL dolt_commit('-a', '-m', 'cm3');", 1644 }, 1645 Assertions: []queries.ScriptTestAssertion{ 1646 { 1647 Query: "CALL dolt_merge('test');", 1648 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1649 }, 1650 { 1651 Query: "INSERT INTO t VALUES (NULL,6),(7,7),(NULL,8);", 1652 Expected: []sql.Row{{types.OkResult{RowsAffected: 3, InsertID: 6}}}, 1653 }, 1654 { 1655 Query: "SELECT * FROM t ORDER BY pk;", 1656 Expected: []sql.Row{ 1657 {1, 1}, 1658 {3, 3}, 1659 {4, 4}, 1660 {5, 5}, 1661 {6, 6}, 1662 {7, 7}, 1663 {8, 8}, 1664 }, 1665 }, 1666 }, 1667 }, 1668 { 1669 Name: "dolt_merge() with a gap in an auto increment key", 1670 SetUpScript: []string{ 1671 "CREATE TABLE t (pk int PRIMARY KEY AUTO_INCREMENT, c0 int);", 1672 "INSERT INTO t (c0) VALUES (1), (2);", 1673 "CALL dolt_add('-A');", 1674 "CALL dolt_commit('-am', 'cm1');", 1675 "CALL dolt_checkout('-b', 'test');", 1676 "INSERT INTO t VALUES (4,4), (5,5);", 1677 "CALL dolt_commit('-am', 'cm2');", 1678 "CALL dolt_checkout('main');", 1679 }, 1680 Assertions: []queries.ScriptTestAssertion{ 1681 { 1682 Query: "CALL dolt_merge('test');", 1683 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 1684 }, 1685 { 1686 Query: "INSERT INTO t VALUES (3,3),(NULL,6);", 1687 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 3}}}, 1688 }, 1689 { 1690 Query: "SELECT * FROM t ORDER BY pk;", 1691 Expected: []sql.Row{ 1692 {1, 1}, 1693 {2, 2}, 1694 {3, 3}, 1695 {4, 4}, 1696 {5, 5}, 1697 {6, 6}, 1698 }, 1699 }, 1700 }, 1701 }, 1702 { 1703 Name: "dolt_merge() (3way) with a gap in an auto increment key", 1704 SetUpScript: []string{ 1705 "CREATE TABLE t (pk int PRIMARY KEY AUTO_INCREMENT, c0 int);", 1706 "INSERT INTO t (c0) VALUES (1);", 1707 "CALL dolt_add('-A');", 1708 "CALL dolt_commit('-am', 'cm1');", 1709 "CALL dolt_checkout('-b', 'test');", 1710 "INSERT INTO t VALUES (4,4), (5,5);", 1711 "CALL dolt_commit('-am', 'cm2');", 1712 "CALL dolt_checkout('main');", 1713 "INSERT INTO t (c0) VALUES (6);", 1714 "CALL dolt_commit('-am', 'cm3');", 1715 }, 1716 Assertions: []queries.ScriptTestAssertion{ 1717 { 1718 Query: "CALL dolt_merge('test');", 1719 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1720 }, 1721 { 1722 Query: "INSERT INTO t VALUES (3,3),(NULL,7);", 1723 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 3}}}, 1724 }, 1725 { 1726 Query: "SELECT * FROM t ORDER BY pk;", 1727 Expected: []sql.Row{ 1728 {1, 1}, 1729 {3, 3}, 1730 {4, 4}, 1731 {5, 5}, 1732 {6, 6}, 1733 {7, 7}, 1734 }, 1735 }, 1736 }, 1737 }, 1738 { 1739 Name: "add multiple columns, then set and unset a value. No conflicts expected.", 1740 SetUpScript: []string{ 1741 "CREATE table t (pk int primary key);", 1742 "Insert into t values (1), (2);", 1743 "alter table t add column col1 int;", 1744 "alter table t add column col2 int;", 1745 "CALL DOLT_ADD('.');", 1746 "CALL DOLT_COMMIT('-am', 'setup');", 1747 "CALL DOLT_CHECKOUT('-b', 'right');", 1748 "update t set col1 = 1 where pk = 1;", 1749 "update t set col1 = null where pk = 1;", 1750 "CALL DOLT_COMMIT('--allow-empty', '-am', 'right cm');", 1751 "CALL DOLT_CHECKOUT('main');", 1752 "DELETE from t where pk = 1;", 1753 "CALL DOLT_COMMIT('-am', 'left cm');", 1754 }, 1755 Assertions: []queries.ScriptTestAssertion{ 1756 { 1757 Query: "CALL DOLT_MERGE('right');", 1758 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1759 }, 1760 { 1761 Query: "SELECT * FROM t;", 1762 Expected: []sql.Row{{2, nil, nil}}, 1763 }, 1764 }, 1765 }, 1766 { 1767 Name: "dropping constraint from one branch drops from both", 1768 SetUpScript: []string{ 1769 "create table t (i int)", 1770 "alter table t add constraint c check (i > 0)", 1771 "call dolt_commit('-Am', 'initial commit')", 1772 1773 "call dolt_checkout('-b', 'other')", 1774 "insert into t values (1)", 1775 "call dolt_commit('-Am', 'changes to other')", 1776 1777 "call dolt_checkout('main')", 1778 "alter table t drop constraint c", 1779 "call dolt_commit('-Am', 'changes to main')", 1780 }, 1781 Assertions: []queries.ScriptTestAssertion{ 1782 { 1783 Query: "CALL DOLT_MERGE('other');", 1784 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1785 }, 1786 { 1787 Query: "select * from t", 1788 Expected: []sql.Row{{1}}, 1789 }, 1790 }, 1791 }, 1792 { 1793 Name: "dropping constraint from one branch drops from both, no checkout", 1794 SetUpScript: []string{ 1795 "create table t (i int)", 1796 "alter table t add constraint c check (i > 0)", 1797 "call dolt_commit('-Am', 'initial commit')", 1798 1799 "call dolt_branch('other')", 1800 "use mydb/other", 1801 "insert into t values (1)", 1802 "alter table t drop constraint c", 1803 "call dolt_commit('-Am', 'changes to other')", 1804 1805 "use mydb/main", 1806 }, 1807 Assertions: []queries.ScriptTestAssertion{ 1808 { 1809 Query: "insert into t values (-1)", 1810 ExpectedErr: sql.ErrCheckConstraintViolated, 1811 }, 1812 { 1813 Query: "CALL DOLT_MERGE('other');", 1814 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 1815 }, 1816 { 1817 Query: "select * from t", 1818 Expected: []sql.Row{{1}}, 1819 }, 1820 { 1821 Query: "insert into t values (-1)", 1822 Expected: []sql.Row{{types.NewOkResult(1)}}, 1823 }, 1824 }, 1825 }, 1826 { 1827 Name: "merge constraint with valid data on different branches", 1828 SetUpScript: []string{ 1829 "create table t (i int)", 1830 "call dolt_commit('-Am', 'initial commit')", 1831 1832 "call dolt_checkout('-b', 'other')", 1833 "insert into t values (1)", 1834 "call dolt_commit('-Am', 'changes to other')", 1835 1836 "call dolt_checkout('main')", 1837 "alter table t add check (i < 10)", 1838 "call dolt_commit('-Am', 'changes to main')", 1839 }, 1840 Assertions: []queries.ScriptTestAssertion{ 1841 { 1842 Query: "CALL DOLT_MERGE('other');", 1843 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1844 }, 1845 { 1846 Query: "select * from t", 1847 Expected: []sql.Row{{1}}, 1848 }, 1849 }, 1850 }, 1851 { 1852 Name: "resolving a deleted and modified row handles constraint checks", 1853 SetUpScript: []string{ 1854 "create table test(a int primary key, b int, c int );", 1855 "alter table test add check (b < 4);", 1856 "insert into test values (1, 2, 3);", 1857 "call dolt_add('test');", 1858 "call dolt_commit('-m', 'create test table');", 1859 1860 "call dolt_checkout('-b', 'other');", 1861 "alter table test drop column c;", 1862 "call dolt_add('test');", 1863 "call dolt_commit('-m', 'drop column');", 1864 1865 "call dolt_checkout('main');", 1866 "delete from test;", 1867 "call dolt_add('test');", 1868 "call dolt_commit('-m', 'remove row');", 1869 }, 1870 Assertions: []queries.ScriptTestAssertion{ 1871 { 1872 Query: "CALL DOLT_MERGE('other');", 1873 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1874 }, 1875 { 1876 Query: "select * from test", 1877 Expected: []sql.Row{}, 1878 }, 1879 }, 1880 }, 1881 { 1882 Name: "resolving a modified/modified row still checks nullness constraint", 1883 SetUpScript: []string{ 1884 "create table test(a int primary key, b int, c int);", 1885 "insert into test values (1, 2, 3);", 1886 "call dolt_add('test');", 1887 "call dolt_commit('-m', 'create test table');", 1888 1889 "call dolt_checkout('-b', 'other');", 1890 "alter table test modify c int not null;", 1891 "update test set b = NULL;", 1892 "call dolt_add('test');", 1893 "call dolt_commit('-m', 'drop column');", 1894 1895 "call dolt_checkout('main');", 1896 "alter table test modify b int not null", 1897 "update test set c = NULL;", 1898 "call dolt_add('test');", 1899 "call dolt_commit('-m', 'remove row');", 1900 "set dolt_force_transaction_commit = on;", 1901 }, 1902 Assertions: []queries.ScriptTestAssertion{ 1903 { 1904 Query: "CALL DOLT_MERGE('other');", 1905 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 1906 }, 1907 { 1908 Query: "select a, b, c from dolt_constraint_violations_test;", 1909 Expected: []sql.Row{{1, nil, nil}}, 1910 }, 1911 }, 1912 }, 1913 { 1914 Name: "Pk convergent updates to sec diff congruent", 1915 SetUpScript: []string{ 1916 "create table xyz (x int primary key, y int, z int, key y_idx(y), key z_idx(z))", 1917 "insert into xyz values (0,0,0), (1,1,1)", 1918 "call dolt_commit('-Am', 'make table')", 1919 1920 "call dolt_checkout('-b', 'feature')", 1921 "update xyz set z = 2 where z = 1", 1922 "call dolt_commit('-am', 'update z=2')", 1923 1924 "call dolt_checkout('main')", 1925 "update xyz set y = 2 where z = 1", 1926 "call dolt_commit('-am', 'update y=2')", 1927 }, 1928 Assertions: []queries.ScriptTestAssertion{ 1929 { 1930 Query: "CALL DOLT_MERGE('feature');", 1931 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1932 }, 1933 { 1934 Query: "select y from xyz where y >= 0", 1935 Expected: []sql.Row{{0}, {2}}, 1936 }, 1937 { 1938 Query: "select z from xyz where y >= 0", 1939 Expected: []sql.Row{{0}, {2}}, 1940 }, 1941 }, 1942 }, 1943 { 1944 Name: "Pk convergent left and right adds", 1945 SetUpScript: []string{ 1946 "create table xyz (x int primary key, y int, z int, key y_idx(y), key z_idx(z))", 1947 "insert into xyz values (0,0,0)", 1948 "call dolt_commit('-Am', 'make table')", 1949 1950 "call dolt_checkout('-b', 'feature')", 1951 "insert into xyz values (1,1,1)", 1952 "call dolt_commit('-am', 'adds')", 1953 1954 "call dolt_checkout('main')", 1955 "insert into xyz values (1,1,1), (2,2,2)", 1956 "call dolt_commit('-am', 'adds')", 1957 }, 1958 Assertions: []queries.ScriptTestAssertion{ 1959 { 1960 Query: "CALL DOLT_MERGE('feature');", 1961 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1962 }, 1963 { 1964 Query: "select y from xyz where y >= 0", 1965 Expected: []sql.Row{{0}, {1}, {2}}, 1966 }, 1967 { 1968 Query: "select z from xyz where y >= 0", 1969 Expected: []sql.Row{{0}, {1}, {2}}, 1970 }, 1971 }, 1972 }, 1973 { 1974 Name: "Pk adds+convergent adds to sec congruent", 1975 SetUpScript: []string{ 1976 "create table xyz (x int primary key, y int, z int, key y_idx(y), key z_idx(z))", 1977 "insert into xyz values (0,0,0), (1,1,1)", 1978 "call dolt_commit('-Am', 'make table')", 1979 1980 "call dolt_checkout('-b', 'feature')", 1981 "insert into xyz values (3,3,3)", 1982 "update xyz set z = 5 where z = 1", 1983 "call dolt_commit('-am', 'right adds + edit')", 1984 1985 "call dolt_checkout('main')", 1986 "insert into xyz values (4,4,4)", 1987 "update xyz set y = 2 where z = 1", 1988 "call dolt_commit('-am', 'left adds + update')", 1989 }, 1990 Assertions: []queries.ScriptTestAssertion{ 1991 { 1992 Query: "CALL DOLT_MERGE('feature');", 1993 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 1994 }, 1995 { 1996 Query: "select y from xyz where y >= 0 order by 1", 1997 Expected: []sql.Row{{0}, {2}, {3}, {4}}, 1998 }, 1999 { 2000 Query: "select z from xyz where y >= 0 order by 1", 2001 Expected: []sql.Row{{0}, {3}, {4}, {5}}, 2002 }, 2003 }, 2004 }, 2005 { 2006 Name: "Left deletes", 2007 SetUpScript: []string{ 2008 "create table xyz (x int primary key, y int, z int, key y_idx(y), key z_idx(z))", 2009 "insert into xyz values (0,0,0), (1,1,1),(2,2,2),(3,3,3)", 2010 "call dolt_commit('-Am', 'make table')", 2011 2012 "call dolt_checkout('-b', 'feature')", 2013 "delete from xyz where y = 3", 2014 "call dolt_commit('-am', 'right deletes')", 2015 2016 "call dolt_checkout('main')", 2017 "delete from xyz where y = 1", 2018 "call dolt_commit('-am', 'left deletes')", 2019 }, 2020 Assertions: []queries.ScriptTestAssertion{ 2021 { 2022 Query: "CALL DOLT_MERGE('feature');", 2023 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 2024 }, 2025 { 2026 Query: "select y from xyz where y >= 0 order by 1", 2027 Expected: []sql.Row{{0}, {2}}, 2028 }, 2029 { 2030 Query: "select z from xyz where y >= 0 order by 1", 2031 Expected: []sql.Row{{0}, {2}}, 2032 }, 2033 }, 2034 }, 2035 { 2036 Name: "delete conflict", 2037 SetUpScript: []string{ 2038 "set @@dolt_allow_commit_conflicts = 1", 2039 "create table xyz (x int primary key, y int, z int, key y_idx(y), key z_idx(z))", 2040 "insert into xyz values (0,0,0), (1,1,1)", 2041 "call dolt_commit('-Am', 'make table')", 2042 2043 "call dolt_checkout('-b', 'feature')", 2044 "delete from xyz where y = 1", 2045 "call dolt_commit('-am', 'right delete')", 2046 2047 "call dolt_checkout('main')", 2048 "update xyz set y = 2 where y = 1", 2049 "call dolt_commit('-am', 'left update')", 2050 }, 2051 Assertions: []queries.ScriptTestAssertion{ 2052 { 2053 Query: "CALL DOLT_MERGE('feature');", 2054 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 2055 }, 2056 { 2057 Query: "select our_y, our_diff_type, their_y, their_diff_type from dolt_conflicts_xyz", 2058 Expected: []sql.Row{{2, "modified", nil, "removed"}}, 2059 }, 2060 }, 2061 }, 2062 { 2063 Name: "divergent edit conflict", 2064 SetUpScript: []string{ 2065 "set @@dolt_allow_commit_conflicts = 1", 2066 "create table xyz (x int primary key, y int, z int, key y_idx(y), key z_idx(z))", 2067 "insert into xyz values (0,0,0), (1,1,1)", 2068 "call dolt_commit('-Am', 'make table')", 2069 2070 "call dolt_checkout('-b', 'feature')", 2071 "update xyz set y = 3 where y = 1", 2072 "call dolt_commit('-am', 'right delete')", 2073 2074 "call dolt_checkout('main')", 2075 "update xyz set y = 2 where y = 1", 2076 "call dolt_commit('-am', 'left update')", 2077 }, 2078 Assertions: []queries.ScriptTestAssertion{ 2079 { 2080 Query: "CALL DOLT_MERGE('feature');", 2081 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 2082 }, 2083 { 2084 Query: "select our_y, our_diff_type, their_y, their_diff_type from dolt_conflicts_xyz", 2085 Expected: []sql.Row{{2, "modified", 3, "modified"}}, 2086 }, 2087 }, 2088 }, 2089 { 2090 Name: "Merge errors if the primary key types have changed (even if the new type has the same NomsKind)", 2091 SetUpScript: []string{ 2092 "CREATE TABLE t (pk1 bigint, pk2 bigint, PRIMARY KEY (pk1, pk2));", 2093 "CALL DOLT_ADD('.')", 2094 "CALL DOLT_COMMIT('-am', 'setup');", 2095 2096 "CALL DOLT_CHECKOUT('-b', 'right');", 2097 "ALTER TABLE t MODIFY COLUMN pk2 tinyint", 2098 "INSERT INTO t VALUES (2, 2);", 2099 "CALL DOLT_COMMIT('-am', 'right commit');", 2100 2101 "CALL DOLT_CHECKOUT('main');", 2102 "INSERT INTO t VALUES (1, 1);", 2103 "CALL DOLT_COMMIT('-am', 'left commit');", 2104 }, 2105 Assertions: []queries.ScriptTestAssertion{ 2106 { 2107 Query: "CALL DOLT_MERGE('right');", 2108 ExpectedErrStr: "error: cannot merge because table t has different primary keys", 2109 }, 2110 }, 2111 }, 2112 { 2113 Name: "`Delete from table` should keep artifacts - conflicts", 2114 SetUpScript: createConflictsSetupScript, 2115 Assertions: []queries.ScriptTestAssertion{ 2116 { 2117 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2118 Expected: []sql.Row{ 2119 {nil, nil, 1, -100, 1, 100}, 2120 {nil, nil, 2, -200, 2, 200}, 2121 }, 2122 }, 2123 { 2124 Query: "delete from t;", 2125 Expected: []sql.Row{{types.NewOkResult(2)}}, 2126 }, 2127 { 2128 Query: "select * from t;", 2129 Expected: []sql.Row{}, 2130 }, 2131 { 2132 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2133 Expected: []sql.Row{ 2134 {nil, nil, nil, nil, 1, 100}, 2135 {nil, nil, nil, nil, 2, 200}, 2136 }, 2137 }, 2138 }, 2139 }, 2140 { 2141 Name: "`Truncate table` should keep artifacts - conflicts", 2142 SetUpScript: createConflictsSetupScript, 2143 Assertions: []queries.ScriptTestAssertion{ 2144 { 2145 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2146 Expected: []sql.Row{ 2147 {nil, nil, 1, -100, 1, 100}, 2148 {nil, nil, 2, -200, 2, 200}, 2149 }, 2150 }, 2151 { 2152 Query: "truncate t;", 2153 Expected: []sql.Row{{types.NewOkResult(2)}}, 2154 }, 2155 { 2156 Query: "select * from t;", 2157 Expected: []sql.Row{}, 2158 }, 2159 { 2160 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2161 Expected: []sql.Row{ 2162 {nil, nil, nil, nil, 1, 100}, 2163 {nil, nil, nil, nil, 2, 200}, 2164 }, 2165 }, 2166 }, 2167 }, 2168 { 2169 Name: "`Delete from table` should keep artifacts - violations", 2170 SetUpScript: createViolationsSetupScript, 2171 Assertions: []queries.ScriptTestAssertion{ 2172 { 2173 Query: "select pk, col1 from dolt_constraint_violations_t;", 2174 Expected: []sql.Row{{1, 1}, {2, 1}}, 2175 }, 2176 { 2177 Query: "delete from t;", 2178 Expected: []sql.Row{{types.NewOkResult(4)}}, 2179 }, 2180 { 2181 Query: "select * from t;", 2182 Expected: []sql.Row{}, 2183 }, 2184 { 2185 Query: "select pk, col1 from dolt_constraint_violations_t;", 2186 Expected: []sql.Row{{1, 1}, {2, 1}}, 2187 }, 2188 }, 2189 }, 2190 { 2191 Name: "`Truncate table` should keep artifacts - violations", 2192 SetUpScript: createViolationsSetupScript, 2193 Assertions: []queries.ScriptTestAssertion{ 2194 { 2195 Query: "select pk, col1 from dolt_constraint_violations_t;", 2196 Expected: []sql.Row{{1, 1}, {2, 1}}, 2197 }, 2198 { 2199 Query: "truncate t;", 2200 Expected: []sql.Row{{types.NewOkResult(4)}}, 2201 }, 2202 { 2203 Query: "select * from t;", 2204 Expected: []sql.Row{}, 2205 }, 2206 { 2207 Query: "select pk, col1 from dolt_constraint_violations_t;", 2208 Expected: []sql.Row{{1, 1}, {2, 1}}, 2209 }, 2210 }, 2211 }, 2212 { 2213 Name: "parent index is longer than child index", 2214 SetUpScript: []string{ 2215 "create table parent (i int primary key, x int, y int, z int, index (y, x, z));", 2216 "create table child (y int, x int, primary key(y, x), foreign key (y, x) references parent(y, x));", 2217 "insert into parent values (100,1,1,1), (200,2,1,2), (300,1,null,1);", 2218 "CALL DOLT_ADD('.')", 2219 "CALL DOLT_COMMIT('-am', 'setup');", 2220 "CALL DOLT_BRANCH('other');", 2221 2222 "DELETE from parent WHERE x = 2;", 2223 "CALL DOLT_COMMIT('-am', 'main');", 2224 2225 "CALL DOLT_CHECKOUT('other');", 2226 "INSERT INTO child VALUES (1, 2);", 2227 "CALL DOLT_COMMIT('-am', 'other');", 2228 2229 "CALL DOLT_CHECKOUT('main');", 2230 "set DOLT_FORCE_TRANSACTION_COMMIT = on;", 2231 "CALL DOLT_MERGE('other');", 2232 }, 2233 Assertions: []queries.ScriptTestAssertion{ 2234 { 2235 Query: "SELECT * from dolt_constraint_violations", 2236 Expected: []sql.Row{ 2237 {"child", uint64(1)}, 2238 }, 2239 }, 2240 { 2241 Query: "SELECT * from dolt_constraint_violations_parent", 2242 Expected: []sql.Row{}, 2243 }, 2244 { 2245 Query: "SELECT y, x from dolt_constraint_violations_child", 2246 Expected: []sql.Row{ 2247 {1, 2}, 2248 }, 2249 }, 2250 }, 2251 }, 2252 { 2253 Name: "parallel column updates (repro issue #4547)", 2254 SetUpScript: []string{ 2255 "SET dolt_allow_commit_conflicts = on;", 2256 "create table t (rowId int not null, col1 varchar(255), col2 varchar(255), keyCol varchar(60), dataA varchar(255), dataB varchar(255), PRIMARY KEY (rowId), UNIQUE KEY uniqKey (col1, col2, keyCol));", 2257 "insert into t (rowId, col1, col2, keyCol, dataA, dataB) values (1, '1', '2', 'key-a', 'test1', 'test2')", 2258 "CALL DOLT_COMMIT('-Am', 'new table');", 2259 2260 "CALL DOLT_CHECKOUT('-b', 'other');", 2261 "update t set dataA = 'other'", 2262 "CALL DOLT_COMMIT('-am', 'update data other');", 2263 2264 "CALL DOLT_CHECKOUT('main');", 2265 "update t set dataB = 'main'", 2266 "CALL DOLT_COMMIT('-am', 'update on main');", 2267 }, 2268 Assertions: []queries.ScriptTestAssertion{ 2269 { 2270 Query: "CALL DOLT_MERGE('other')", 2271 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 2272 }, 2273 { 2274 Query: "SELECT * from dolt_constraint_violations_t", 2275 Expected: []sql.Row{}, 2276 }, 2277 { 2278 Query: "SELECT * from t", 2279 Expected: []sql.Row{ 2280 {1, "1", "2", "key-a", "other", "main"}, 2281 }, 2282 }, 2283 }, 2284 }, 2285 { 2286 Name: "try to merge a nullable field into a non-null column", 2287 SetUpScript: []string{ 2288 "SET dolt_force_transaction_commit = on;", 2289 "create table test (pk int primary key, c0 int)", 2290 "insert into test values (1,1),(3,3);", 2291 "call dolt_commit('-Am', 'new table with NULL value');", 2292 "call dolt_checkout('-b', 'other')", 2293 "insert into test values (2,NULL);", 2294 "call dolt_commit('-am', 'inserted null value')", 2295 "call dolt_checkout('main');", 2296 "alter table test modify c0 int not null;", 2297 "insert into test values (4,4)", 2298 "call dolt_commit('-am', 'modified column c0 to not null');", 2299 }, 2300 Assertions: []queries.ScriptTestAssertion{ 2301 { 2302 Query: "call dolt_merge('other')", 2303 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 2304 }, 2305 { 2306 Query: "select * from dolt_constraint_violations", 2307 Expected: []sql.Row{{"test", uint(1)}}, 2308 }, 2309 { 2310 Query: "select violation_type, pk, violation_info from dolt_constraint_violations_test", 2311 Expected: []sql.Row{ 2312 {"not null", 2, merge.NullViolationMeta{Columns: []string{"c0"}}}, 2313 }, 2314 }, 2315 }, 2316 }, 2317 { 2318 Name: "merge fulltext with renamed table", 2319 SetUpScript: []string{ 2320 "CREATE TABLE test (pk BIGINT UNSIGNED PRIMARY KEY, v1 VARCHAR(200), FULLTEXT idx (v1));", 2321 "INSERT INTO test VALUES (1, 'abc');", 2322 "CALL dolt_commit('-Am', 'Initial commit')", 2323 "call dolt_branch('other')", 2324 "DROP INDEX idx ON test;", 2325 "INSERT INTO test VALUES (2, 'def');", 2326 "RENAME TABLE test TO test_temp;", 2327 "ALTER TABLE test_temp ADD FULLTEXT INDEX idx (v1);", 2328 "RENAME TABLE test_temp TO test;", 2329 "call dolt_commit('-Am', 'Renamed pseudo-index tables')", 2330 "call dolt_checkout('other')", 2331 "INSERT INTO test VALUES (3, 'ghi');", 2332 "call dolt_commit('-Am', 'Insertion commit')", 2333 "call dolt_checkout('main')", 2334 }, 2335 Assertions: []queries.ScriptTestAssertion{ 2336 { 2337 Query: "call dolt_merge('other')", 2338 SkipResultsCheck: true, // contains commit hash, we just need it to not error 2339 }, 2340 { 2341 Query: "SELECT v1 FROM test WHERE MATCH(v1) AGAINST ('abc def ghi');", 2342 Expected: []sql.Row{ 2343 {"abc"}, 2344 {"def"}, 2345 {"ghi"}, 2346 }, 2347 }, 2348 }, 2349 }, 2350 { 2351 Name: "merge when schemas are equal, but column tags are different", 2352 SetUpScript: []string{ 2353 // Create a branch where t doesn't exist yet 2354 "call dolt_branch('branch1');", 2355 // Create t on main, but change column types so that the tag won't match branch1 2356 "CREATE TABLE t (pk INT PRIMARY KEY, col1 int);", 2357 "call dolt_commit('-Am', 'creating table t on main');", 2358 "ALTER TABLE t modify column col1 varchar(255);", 2359 "call dolt_commit('-am', 'modifying table t on main');", 2360 "INSERT INTO t values (1, 'one'), (2, 'two');", 2361 "call dolt_commit('-am', 'inserting two rows into t on main');", 2362 2363 // Create t on branch1, without an intermediate type change, so that the tag doesn't match main 2364 "call dolt_checkout('branch1');", 2365 "CREATE TABLE t (pk INT PRIMARY KEY, col1 varchar(255));", 2366 "call dolt_commit('-Am', 'creating table t on branch1');", 2367 "INSERT INTO t values (3, 'three');", 2368 "call dolt_commit('-am', 'inserting one row into t on branch1');", 2369 "SET @PreMergeBranch1Commit = dolt_hashof('HEAD');", 2370 }, 2371 Assertions: []queries.ScriptTestAssertion{ 2372 { 2373 // We can merge from main -> branch1, even though the column tags are not identical 2374 Query: "call dolt_merge('main')", 2375 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 2376 }, 2377 { 2378 Query: "SELECT * FROM t;", 2379 Expected: []sql.Row{{1, "one"}, {2, "two"}, {3, "three"}}, 2380 }, 2381 { 2382 // Reset branch1 to the pre-merge commit, so we can test merging branch1 -> main 2383 Query: "CALL dolt_reset('--hard', @PreMergeBranch1Commit);", 2384 Expected: []sql.Row{{0}}, 2385 }, 2386 { 2387 Query: "CALL dolt_checkout('main');", 2388 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 2389 }, 2390 { 2391 // We can merge from branch1 -> main, even though the column tags are not identical 2392 Query: "call dolt_merge('branch1')", 2393 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 2394 }, 2395 { 2396 Query: "SELECT * FROM t;", 2397 Expected: []sql.Row{{1, "one"}, {2, "two"}, {3, "three"}}, 2398 }, 2399 }, 2400 }, 2401 } 2402 2403 var KeylessMergeCVsAndConflictsScripts = []queries.ScriptTest{ 2404 { 2405 Name: "Keyless merge with unique indexes documents violations", 2406 SetUpScript: []string{ 2407 "SET dolt_force_transaction_commit = on;", 2408 "CREATE table t (col1 int, col2 int UNIQUE);", 2409 "CALL DOLT_ADD('.')", 2410 "CALL DOLT_COMMIT('-am', 'setup');", 2411 2412 "CALL DOLT_CHECKOUT('-b', 'right');", 2413 "INSERT INTO t VALUES (2, 1);", 2414 "CALL DOLT_COMMIT('-am', 'right');", 2415 2416 "CALL DOLT_CHECKOUT('main');", 2417 "INSERT INTO t values (1, 1);", 2418 "CALL DOLT_COMMIT('-am', 'left');", 2419 }, 2420 Assertions: []queries.ScriptTestAssertion{ 2421 { 2422 Query: "CALL DOLT_MERGE('right');", 2423 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 2424 }, 2425 { 2426 Query: "SELECT violation_type, col1, col2 from dolt_constraint_violations_t ORDER BY col1 ASC;", 2427 Expected: []sql.Row{{"unique index", 1, 1}, {"unique index", 2, 1}}, 2428 }, 2429 { 2430 Query: "SELECT * from t ORDER BY col1 ASC;", 2431 Expected: []sql.Row{{1, 1}, {2, 1}}, 2432 }, 2433 }, 2434 }, 2435 { 2436 Name: "Keyless merge with foreign keys documents violations", 2437 SetUpScript: []string{ 2438 "SET dolt_force_transaction_commit = on;", 2439 "CREATE table parent (pk int PRIMARY KEY);", 2440 "CREATE table child (parent_fk int, FOREIGN KEY (parent_fk) REFERENCES parent (pk));", 2441 "CALL DOLT_ADD('.')", 2442 "INSERT INTO parent VALUES (1);", 2443 "CALL DOLT_COMMIT('-am', 'setup');", 2444 2445 "CALL DOLT_CHECKOUT('-b', 'right');", 2446 "INSERT INTO child VALUES (1);", 2447 "CALL DOLT_COMMIT('-am', 'right');", 2448 2449 "CALL DOLT_CHECKOUT('main');", 2450 "DELETE from parent where pk = 1;", 2451 "CALL DOLT_COMMIT('-am', 'left');", 2452 }, 2453 Assertions: []queries.ScriptTestAssertion{ 2454 { 2455 Query: "CALL DOLT_MERGE('right');", 2456 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 2457 }, 2458 { 2459 Query: "SELECT violation_type, parent_fk from dolt_constraint_violations_child;", 2460 Expected: []sql.Row{{"foreign key", 1}}, 2461 }, 2462 { 2463 Query: "SELECT * from parent;", 2464 Expected: []sql.Row{}, 2465 }, 2466 { 2467 Query: "SELECT * from child;", 2468 Expected: []sql.Row{{1}}, 2469 }, 2470 }, 2471 }, 2472 { 2473 Name: "Keyless merge documents conflicts", 2474 SetUpScript: []string{ 2475 "SET dolt_allow_commit_conflicts = on;", 2476 "CREATE table t (col1 int, col2 int);", 2477 "CALL DOLT_ADD('.')", 2478 "CALL DOLT_COMMIT('-am', 'setup');", 2479 2480 "CALL DOLT_CHECKOUT('-b', 'right');", 2481 "INSERT INTO t VALUES (1, 1);", 2482 "CALL DOLT_COMMIT('-am', 'right');", 2483 2484 "CALL DOLT_CHECKOUT('main');", 2485 "INSERT INTO t VALUES (1, 1);", 2486 "CALL DOLT_COMMIT('-am', 'left');", 2487 }, 2488 Assertions: []queries.ScriptTestAssertion{ 2489 { 2490 Query: "CALL DOLT_MERGE('right');", 2491 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 2492 }, 2493 { 2494 Query: "SELECT base_col1, base_col2, our_col1, our_col2, their_col1, their_col2 from dolt_conflicts_t;", 2495 Expected: []sql.Row{{nil, nil, 1, 1, 1, 1}}, 2496 }, 2497 }, 2498 }, 2499 { 2500 // this won't automatically become a PK because col2 is nullable 2501 Name: "unique key violation for keyless table", 2502 SetUpScript: []string{ 2503 "create table t (col1 int not null, col2 int, col3 int);", 2504 "alter table t add unique index (col1, col2);", 2505 "call dolt_commit('-Am', 'init');", 2506 2507 "call dolt_checkout('-b', 'right');", 2508 "insert into t values (1, null, null);", 2509 "insert into t values (3, 3, null);", 2510 "call dolt_commit('-Am', 'right cm');", 2511 2512 "call dolt_checkout('main');", 2513 "insert into t values (2, null, null);", 2514 "insert into t values (3, 3, 1);", 2515 "call dolt_commit('-Am', 'left cm');", 2516 2517 "set dolt_force_transaction_commit = 1;", 2518 }, 2519 Assertions: []queries.ScriptTestAssertion{ 2520 { 2521 Query: "call dolt_merge('right');", 2522 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 2523 }, 2524 { 2525 Query: "select col1, col2, col3 from dolt_constraint_violations_t;", 2526 Expected: []sql.Row{{3, 3, nil}, {3, 3, 1}}, 2527 }, 2528 }, 2529 }, 2530 } 2531 2532 var DoltConflictTableNameTableTests = []queries.ScriptTest{ 2533 { 2534 Name: "conflict diff types", 2535 SetUpScript: []string{ 2536 "SET dolt_allow_commit_conflicts = on;", 2537 "CREATE table t (pk int PRIMARY KEY, col1 int);", 2538 "CALL DOLT_ADD('.')", 2539 "INSERT INTO t VALUES (1, 1);", 2540 "INSERT INTO t VALUES (2, 2);", 2541 "INSERT INTO t VALUES (3, 3);", 2542 "CALL DOLT_COMMIT('-am', 'create table with row');", 2543 2544 "CALL DOLT_CHECKOUT('-b', 'other');", 2545 "UPDATE t set col1 = 3 where pk = 1;", 2546 "UPDATE t set col1 = 0 where pk = 2;", 2547 "DELETE FROM t where pk = 3;", 2548 "INSERT INTO t VALUES (4, -4);", 2549 "CALL DOLT_COMMIT('-am', 'right edit');", 2550 2551 "CALL DOLT_CHECKOUT('main');", 2552 "UPDATE t set col1 = 2 where pk = 1;", 2553 "DELETE FROM t where pk = 2;", 2554 "UPDATE t set col1 = 0 where pk = 3;", 2555 "INSERT INTO t VALUES (4, 4);", 2556 "CALL DOLT_COMMIT('-am', 'left edit');", 2557 }, 2558 Assertions: []queries.ScriptTestAssertion{ 2559 { 2560 Query: "CALL DOLT_MERGE('other');", 2561 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 2562 }, 2563 { 2564 Query: "SELECT base_pk, base_col1, our_pk, our_col1, our_diff_type, their_pk, their_col1, their_diff_type" + 2565 " from dolt_conflicts_t ORDER BY COALESCE(base_pk, our_pk, their_pk) ASC;", 2566 Expected: []sql.Row{ 2567 {1, 1, 1, 2, "modified", 1, 3, "modified"}, 2568 {2, 2, nil, nil, "removed", 2, 0, "modified"}, 2569 {3, 3, 3, 0, "modified", nil, nil, "removed"}, 2570 {nil, nil, 4, 4, "added", 4, -4, "added"}, 2571 }, 2572 }, 2573 }, 2574 }, 2575 { 2576 Name: "keyless cardinality columns", 2577 SetUpScript: []string{ 2578 "SET dolt_allow_commit_conflicts = on;", 2579 "CREATE table t (col1 int);", 2580 "CALL DOLT_ADD('.')", 2581 "INSERT INTO t VALUES (1), (2), (3), (4), (6);", 2582 "CALL DOLT_COMMIT('-am', 'init');", 2583 2584 "CALL DOLT_CHECKOUT('-b', 'right');", 2585 "INSERT INTO t VALUES (1);", 2586 "DELETE FROM t where col1 = 2;", 2587 "INSERT INTO t VALUES (3);", 2588 "INSERT INTO t VALUES (4), (4);", 2589 "INSERT INTO t VALUES (5);", 2590 "DELETE from t where col1 = 6;", 2591 "CALL DOLT_COMMIT('-am', 'right');", 2592 2593 "CALL DOLT_CHECKOUT('main');", 2594 "DELETE FROM t WHERE col1 = 1;", 2595 "INSERT INTO t VALUES (2);", 2596 "INSERT INTO t VALUES (3);", 2597 "INSERT INTO t VALUES (4);", 2598 "INSERT INTO t VALUES (5);", 2599 "DELETE from t where col1 = 6;", 2600 "CALL DOLT_COMMIT('-am', 'left');", 2601 }, 2602 Assertions: []queries.ScriptTestAssertion{ 2603 { 2604 Query: "CALL DOLT_MERGE('right');", 2605 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 2606 }, 2607 { 2608 Query: "SELECT base_col1, our_col1, their_col1, our_diff_type, their_diff_type, base_cardinality, our_cardinality, their_cardinality from dolt_conflicts_t ORDER BY COALESCE(base_col1, our_col1, their_col1) ASC;", 2609 Expected: []sql.Row{ 2610 {1, nil, 1, "removed", "modified", uint64(1), uint64(0), uint64(2)}, 2611 {2, 2, nil, "modified", "removed", uint64(1), uint64(2), uint64(0)}, 2612 {3, 3, 3, "modified", "modified", uint64(1), uint64(2), uint64(2)}, 2613 {4, 4, 4, "modified", "modified", uint64(1), uint64(2), uint64(3)}, 2614 {nil, 5, 5, "added", "added", uint64(0), uint64(1), uint64(1)}, 2615 {6, nil, nil, "removed", "removed", uint64(1), uint64(0), uint64(0)}, 2616 }, 2617 }, 2618 }, 2619 }, 2620 } 2621 2622 var createConflictsSetupScript = []string{ 2623 "create table t (pk int primary key, col1 int);", 2624 "call dolt_commit('-Am', 'create table');", 2625 "call dolt_checkout('-b', 'other');", 2626 2627 "insert into t values (1, 100);", 2628 "insert into t values (2, 200);", 2629 "call dolt_commit('-Am', 'other commit');", 2630 2631 "call dolt_checkout('main');", 2632 "insert into t values (1, -100);", 2633 "insert into t values (2, -200);", 2634 "call dolt_commit('-Am', 'main commit');", 2635 2636 "set dolt_allow_commit_conflicts = on;", 2637 "call dolt_merge('other');", 2638 } 2639 2640 var createViolationsSetupScript = []string{ 2641 "CREATE TABLE t (pk int PRIMARY KEY, col1 int UNIQUE);", 2642 "CALL DOLT_COMMIT('-Am', 'create table');", 2643 2644 "CALL DOLT_CHECKOUT('-b', 'other');", 2645 "INSERT INTO t VALUES (2, 1), (3, 3);", 2646 "CALL DOLT_COMMIT('-am', 'other insert');", 2647 2648 "CALL DOLT_CHECKOUT('main');", 2649 "INSERT INTO t values (1, 1), (4, 4);", 2650 "CALL DOLT_COMMIT('-am', 'main insert');", 2651 2652 "SET dolt_force_transaction_commit = on;", 2653 "call dolt_merge('other');", 2654 } 2655 2656 var Dolt1ConflictTableNameTableTests = []queries.ScriptTest{ 2657 { 2658 Name: "Provides a dolt_conflicts_id", 2659 SetUpScript: createConflictsSetupScript, 2660 Assertions: []queries.ScriptTestAssertion{ 2661 { 2662 Query: "set @hash1 = (select dolt_conflict_id from dolt_conflicts_t where our_pk = 1);", 2663 }, 2664 { 2665 Query: "set @hash2 = (select dolt_conflict_id from dolt_conflicts_t where our_pk = 2);", 2666 }, 2667 { 2668 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t where dolt_conflict_id = @hash1;", 2669 Expected: []sql.Row{ 2670 {nil, nil, 1, -100, 1, 100}, 2671 }, 2672 }, 2673 { 2674 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t where dolt_conflict_id = @hash2;", 2675 Expected: []sql.Row{ 2676 {nil, nil, 2, -200, 2, 200}, 2677 }, 2678 }, 2679 // Make sure that we can update using it 2680 { 2681 Query: "update dolt_conflicts_t SET our_col1 = their_col1 where dolt_conflict_id = @hash1;", 2682 Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, 2683 }, 2684 { 2685 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2686 Expected: []sql.Row{ 2687 {nil, nil, 1, 100, 1, 100}, 2688 {nil, nil, 2, -200, 2, 200}, 2689 }, 2690 }, 2691 // And delete 2692 { 2693 Query: "delete from dolt_conflicts_t where dolt_conflict_id = @hash1;", 2694 Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}}, 2695 }, 2696 { 2697 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2698 Expected: []sql.Row{ 2699 {nil, nil, 2, -200, 2, 200}, 2700 }, 2701 }, 2702 }, 2703 }, 2704 { 2705 Name: "dolt_conflicts_id is unique across merges", 2706 SetUpScript: append(createConflictsSetupScript, []string{ 2707 "CALL DOLT_COMMIT('-afm', 'commit conflicts');", 2708 2709 "CALL DOLT_CHECKOUT('-b', 'other2');", 2710 "UPDATE t SET col1 = 9999 where pk = 1;", 2711 "CALL DOLT_COMMIT('-afm', 'commit on other2');", 2712 2713 "CALL DOLT_CHECKOUT('main');", 2714 "UPDATE t SET col1 = 8888 where pk = 1;", 2715 "CALL DOLT_COMMIT('-afm', 'commit on main');", 2716 2717 "CALL DOLT_MERGE('other2');", 2718 2719 "set @hash1 = (select dolt_conflict_id from dolt_conflicts_t where our_pk = 1 and their_col1 = 100);", 2720 "set @hash2 = (select dolt_conflict_id from dolt_conflicts_t where our_pk = 1 and their_col1 = 9999);", 2721 "set @hash3 = (select dolt_conflict_id from dolt_conflicts_t where our_pk = 2);", 2722 }...), 2723 Assertions: []queries.ScriptTestAssertion{ 2724 { 2725 Query: "select @hash1 != @hash2 AND @hash2 != @hash3;", 2726 Expected: []sql.Row{{true}}, 2727 }, 2728 }, 2729 }, 2730 { 2731 Name: "Updates on our columns get applied to the source table - smoke", 2732 SetUpScript: createConflictsSetupScript, 2733 Assertions: []queries.ScriptTestAssertion{ 2734 { 2735 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2736 Expected: []sql.Row{ 2737 {nil, nil, 1, -100, 1, 100}, 2738 {nil, nil, 2, -200, 2, 200}, 2739 }, 2740 }, 2741 { 2742 Query: "update dolt_conflicts_t set our_col1 = 1000 where our_pk = 1;", 2743 Expected: []sql.Row{{types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Matched: 1, Updated: 1}}}}, 2744 }, 2745 { 2746 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2747 Expected: []sql.Row{ 2748 {nil, nil, 1, 1000, 1, 100}, 2749 {nil, nil, 2, -200, 2, 200}, 2750 }, 2751 }, 2752 { 2753 Query: "select * from t;", 2754 Expected: []sql.Row{ 2755 {1, 1000}, 2756 {2, -200}, 2757 }, 2758 }, 2759 { 2760 Query: "update dolt_conflicts_t set our_col1 = their_col1;", 2761 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, Info: plan.UpdateInfo{Matched: 2, Updated: 2}}}}, 2762 }, 2763 { 2764 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2765 Expected: []sql.Row{ 2766 {nil, nil, 1, 100, 1, 100}, 2767 {nil, nil, 2, 200, 2, 200}, 2768 }, 2769 }, 2770 { 2771 Query: "select * from t;", 2772 Expected: []sql.Row{ 2773 {1, 100}, 2774 {2, 200}, 2775 }, 2776 }, 2777 }, 2778 }, 2779 { 2780 Name: "Updates on our columns get applied to the source table - compound / inverted pks", 2781 SetUpScript: []string{ 2782 "create table t (pk2 int, pk1 int, col1 int, primary key (pk1, pk2));", 2783 "call dolt_commit('-Am', 'create table');", 2784 2785 "call dolt_checkout('-b', 'other');", 2786 "insert into t values (1, 1, 100), (2, 1, 200);", 2787 "call dolt_commit('-Am', 'other commit');", 2788 2789 "call dolt_checkout('main');", 2790 "insert into t values (1, 1, -100), (2, 1, -200);", 2791 "call dolt_commit('-Am', 'main commit');", 2792 2793 "set dolt_allow_commit_conflicts = on;", 2794 "call dolt_merge('other');", 2795 }, 2796 Assertions: []queries.ScriptTestAssertion{ 2797 { 2798 Query: "select base_pk1, base_pk2, base_col1, our_pk1, our_pk2, our_col1, their_pk1, their_pk2, their_col1 from dolt_conflicts_t;", 2799 Expected: []sql.Row{ 2800 {nil, nil, nil, 1, 1, -100, 1, 1, 100}, 2801 {nil, nil, nil, 1, 2, -200, 1, 2, 200}, 2802 }, 2803 }, 2804 { 2805 Query: "Update dolt_conflicts_t set our_col1 = 1000;", 2806 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, Info: plan.UpdateInfo{Matched: 2, Updated: 2}}}}, 2807 }, 2808 { 2809 Query: "select base_pk1, base_pk2, base_col1, our_pk1, our_pk2, our_col1, their_pk1, their_pk2, their_col1 from dolt_conflicts_t;", 2810 Expected: []sql.Row{ 2811 {nil, nil, nil, 1, 1, 1000, 1, 1, 100}, 2812 {nil, nil, nil, 1, 2, 1000, 1, 2, 200}, 2813 }, 2814 }, 2815 { 2816 Query: "select * from t;", 2817 Expected: []sql.Row{ 2818 {1, 1, 1000}, 2819 {2, 1, 1000}, 2820 }, 2821 }, 2822 }, 2823 }, 2824 { 2825 Name: "Updates on our columns get applied to the source table - keyless", 2826 SetUpScript: []string{ 2827 "create table t (name varchar(100), price int);", 2828 "call dolt_commit('-Am', 'create table');", 2829 2830 "call dolt_checkout('-b', 'other');", 2831 "insert into t values ('apple', 1);", 2832 "call dolt_commit('-Am', 'other commit');", 2833 2834 "call dolt_checkout('main');", 2835 "insert into t values ('apple', 1), ('apple', 1);", 2836 "call dolt_commit('-Am', 'main commit');", 2837 2838 "set dolt_allow_commit_conflicts = on;", 2839 "call dolt_merge('other');", 2840 }, 2841 Assertions: []queries.ScriptTestAssertion{ 2842 { 2843 Query: "select base_name, base_price, base_cardinality, our_name, our_price, our_cardinality, their_name, their_price, their_cardinality from dolt_conflicts_t;", 2844 Expected: []sql.Row{ 2845 {nil, nil, uint64(0), "apple", 1, uint64(2), "apple", 1, uint64(1)}, 2846 }, 2847 }, 2848 // Arguably this behavior is weird. If you ran this same query 2849 // against the original table, it would update two rows. Since this 2850 // was run against the conflicts table, only one row is updated. 2851 { 2852 Query: "update dolt_conflicts_t set our_name = 'orange' where our_name = 'apple'", 2853 Expected: []sql.Row{ 2854 {types.OkResult{RowsAffected: 1, Info: plan.UpdateInfo{Updated: 1, Matched: 1}}}, 2855 }, 2856 }, 2857 { 2858 Query: "select base_name, base_price, base_cardinality, our_name, our_price, our_cardinality, their_name, their_price, their_cardinality from dolt_conflicts_t;", 2859 Expected: []sql.Row{ 2860 {nil, nil, uint64(0), "apple", 1, uint64(1), "apple", 1, uint64(1)}, 2861 }, 2862 }, 2863 { 2864 Query: "select * from t;", 2865 Expected: []sql.Row{{"apple", 1}, {"orange", 1}}, 2866 }, 2867 // Updating cardinality should be no-op. 2868 { 2869 Query: "update dolt_conflicts_t set our_cardinality = 10, their_cardinality = 10, base_cardinality = 10;", 2870 }, 2871 { 2872 Query: "select base_name, base_price, base_cardinality, our_name, our_price, our_cardinality, their_name, their_price, their_cardinality from dolt_conflicts_t;", 2873 Expected: []sql.Row{ 2874 {nil, nil, uint64(0), "apple", 1, uint64(1), "apple", 1, uint64(1)}, 2875 }, 2876 }, 2877 { 2878 Query: "select * from t;", 2879 Expected: []sql.Row{{"apple", 1}, {"orange", 1}}, 2880 }, 2881 }, 2882 }, 2883 { 2884 Name: "Updating our cols when the row is missing inserts the row", 2885 SetUpScript: []string{ 2886 "create table t (pk int primary key, col1 int);", 2887 "insert into t values (1, null);", 2888 "insert into t values (2, null);", 2889 "insert into t values (3, null);", 2890 "call dolt_commit('-Am', 'create table');", 2891 "call dolt_checkout('-b', 'other');", 2892 2893 "update t set col1 = 100 where pk = 1;", 2894 "delete from t where pk = 2;", 2895 "update t set col1 = 300 where pk = 3;", 2896 "insert into t values (4, 400);", 2897 "call dolt_commit('-Am', 'other commit');", 2898 2899 "call dolt_checkout('main');", 2900 "update t set col1 = -100 where pk = 1;", 2901 "update t set col1 = -200 where pk = 2;", 2902 "delete from t where pk = 3;", 2903 "insert into t values (4, -400);", 2904 "call dolt_commit('-Am', 'main commit');", 2905 2906 "set dolt_allow_commit_conflicts = on;", 2907 "call dolt_merge('other');", 2908 }, 2909 Assertions: []queries.ScriptTestAssertion{ 2910 { 2911 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2912 Expected: []sql.Row{ 2913 {1, nil, 1, -100, 1, 100}, 2914 {2, nil, 2, -200, nil, nil}, 2915 {3, nil, nil, nil, 3, 300}, 2916 {nil, nil, 4, -400, 4, 400}, 2917 }, 2918 }, 2919 { 2920 Query: "delete from t;", 2921 Expected: []sql.Row{{types.NewOkResult(3)}}, 2922 }, 2923 { 2924 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2925 Expected: []sql.Row{ 2926 {1, nil, nil, nil, 1, 100}, 2927 {2, nil, nil, nil, nil, nil}, 2928 {3, nil, nil, nil, 3, 300}, 2929 {nil, nil, nil, nil, 4, 400}, 2930 }, 2931 }, 2932 { 2933 Query: "select * from t;", 2934 Expected: []sql.Row{}, 2935 }, 2936 // The new rows PKs must be fully specified 2937 { 2938 Query: "update dolt_conflicts_t set our_col1 = their_col1;", 2939 ExpectedErrStr: "column name 'our_pk' is non-nullable but attempted to set a value of null", 2940 }, 2941 // Take theirs 2942 { 2943 Query: "update dolt_conflicts_t set our_pk = their_pk, our_col1 = their_col1;", 2944 Expected: []sql.Row{{types.OkResult{RowsAffected: 3, Info: plan.UpdateInfo{Matched: 4, Updated: 3}}}}, 2945 }, 2946 { 2947 Query: "select * from t;", 2948 Expected: []sql.Row{{1, 100}, {3, 300}, {4, 400}}, 2949 }, 2950 }, 2951 }, 2952 { 2953 Name: "Updating our cols after schema change", 2954 SetUpScript: append(createConflictsSetupScript, "ALTER TABLE t add column col2 int FIRST;"), 2955 Assertions: []queries.ScriptTestAssertion{ 2956 { 2957 Query: "show create table dolt_conflicts_t;", 2958 Expected: []sql.Row{{"dolt_conflicts_t", "CREATE TABLE `dolt_conflicts_t` (\n `from_root_ish` varchar(1023),\n `base_pk` int,\n `base_col1` int,\n `our_pk` int NOT NULL,\n `our_col2` int,\n `our_col1` int,\n `our_diff_type` varchar(1023),\n `their_pk` int,\n `their_col1` int,\n `their_diff_type` varchar(1023),\n `dolt_conflict_id` varchar(1023)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 2959 }, 2960 { 2961 Query: "select base_pk, base_col1, our_pk, our_col1, our_col2, their_pk, their_col1 from dolt_conflicts_t;", 2962 Expected: []sql.Row{ 2963 {nil, nil, 1, -100, nil, 1, 100}, 2964 {nil, nil, 2, -200, nil, 2, 200}, 2965 }, 2966 }, 2967 { 2968 Query: "update dolt_conflicts_t set our_col2 = their_col1", 2969 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, Info: plan.UpdateInfo{Matched: 2, Updated: 2}}}}, 2970 }, 2971 { 2972 Query: "select pk, col1, col2 from t;", 2973 Expected: []sql.Row{ 2974 {1, -100, 100}, 2975 {2, -200, 200}, 2976 }, 2977 }, 2978 }, 2979 }, 2980 { 2981 Name: "Updates on their or base columns do nothing", 2982 SetUpScript: createConflictsSetupScript, 2983 Assertions: []queries.ScriptTestAssertion{ 2984 { 2985 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 2986 Expected: []sql.Row{ 2987 {nil, nil, 1, -100, 1, 100}, 2988 {nil, nil, 2, -200, 2, 200}, 2989 }, 2990 }, 2991 { 2992 Query: "select * from t;", 2993 Expected: []sql.Row{{1, -100}, {2, -200}}, 2994 }, 2995 { 2996 Query: "update dolt_conflicts_t set base_col1 = 9999, their_col1 = 9999;", 2997 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, Info: plan.UpdateInfo{Matched: 2, Updated: 2}}}}, 2998 }, 2999 { 3000 Query: "select base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 3001 Expected: []sql.Row{ 3002 {nil, nil, 1, -100, 1, 100}, 3003 {nil, nil, 2, -200, 2, 200}, 3004 }, 3005 }, 3006 { 3007 Query: "select * from t;", 3008 Expected: []sql.Row{{1, -100}, {2, -200}}, 3009 }, 3010 }, 3011 }, 3012 } 3013 3014 // MergeArtifactsScripts tests new format merge behavior where 3015 // existing violations and conflicts are merged together. 3016 var MergeArtifactsScripts = []queries.ScriptTest{ 3017 { 3018 Name: "conflicts on different branches can be merged", 3019 SetUpScript: []string{ 3020 "SET dolt_allow_commit_conflicts = on", 3021 "CALL DOLT_CHECKOUT('-b', 'conflicts1');", 3022 "CREATE table t (pk int PRIMARY KEY, col1 int);", 3023 "CALL DOLT_ADD('.')", 3024 "CALL DOLT_COMMIT('-am', 'create table');", 3025 "CALL DOLT_BRANCH('conflicts2');", 3026 3027 // branches conflicts1 and conflicts2 both have a table t with no rows 3028 3029 // create a conflict for pk 1 in conflicts1 3030 "INSERT INTO t VALUES (1, 1);", 3031 "CALL DOLT_COMMIT('-am', 'insert pk 1');", 3032 "CALL DOLT_BRANCH('other');", 3033 "UPDATE t set col1 = 100 where pk = 1;", 3034 "CALL DOLT_COMMIT('-am', 'left edit');", 3035 "CALL DOLT_CHECKOUT('other');", 3036 "UPDATE T set col1 = -100 where pk = 1;", 3037 "CALL DOLT_COMMIT('-am', 'right edit');", 3038 "CALL DOLT_CHECKOUT('conflicts1');", 3039 "CALL DOLT_MERGE('other');", 3040 "CALL DOLT_COMMIT('-afm', 'commit conflicts on conflicts1');", 3041 3042 // create a conflict for pk 2 in conflicts2 3043 "CALL DOLT_CHECKOUT('conflicts2');", 3044 "INSERT INTO t VALUES (2, 2);", 3045 "CALL DOLT_COMMIT('-am', 'insert pk 2');", 3046 "CALL DOLT_BRANCH('other2');", 3047 "UPDATE t set col1 = 100 where pk = 2;", 3048 "CALL DOLT_COMMIT('-am', 'left edit');", 3049 "CALL DOLT_CHECKOUT('other2');", 3050 "UPDATE T set col1 = -100 where pk = 2;", 3051 "CALL DOLT_COMMIT('-am', 'right edit');", 3052 "CALL DOLT_CHECKOUT('conflicts2');", 3053 "CALL DOLT_MERGE('other2');", 3054 "CALL DOLT_COMMIT('-afm', 'commit conflicts on conflicts2');", 3055 3056 "CALL DOLT_CHECKOUT('conflicts1');", 3057 }, 3058 Assertions: []queries.ScriptTestAssertion{ 3059 { 3060 Query: "SELECT base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 3061 Expected: []sql.Row{{1, 1, 1, 100, 1, -100}}, 3062 }, 3063 { 3064 Query: "SELECT pk, col1 from t;", 3065 Expected: []sql.Row{{1, 100}}, 3066 }, 3067 { 3068 Query: "CALL DOLT_CHECKOUT('conflicts2');", 3069 Expected: []sql.Row{{0, "Switched to branch 'conflicts2'"}}, 3070 }, 3071 { 3072 Query: "SELECT base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 3073 Expected: []sql.Row{{2, 2, 2, 100, 2, -100}}, 3074 }, 3075 { 3076 Query: "SELECT pk, col1 from t;", 3077 Expected: []sql.Row{{2, 100}}, 3078 }, 3079 { 3080 Query: "CALL DOLT_MERGE('conflicts1');", 3081 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3082 }, 3083 { 3084 Query: "SELECT base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 3085 Expected: []sql.Row{ 3086 {1, 1, 1, 100, 1, -100}, 3087 {2, 2, 2, 100, 2, -100}, 3088 }, 3089 }, 3090 { 3091 Query: "SELECT pk, col1 from t;", 3092 Expected: []sql.Row{ 3093 {1, 100}, 3094 {2, 100}, 3095 }, 3096 }, 3097 { 3098 Query: "UPDATE t SET col1 = 300;", 3099 Expected: []sql.Row{{types.OkResult{ 3100 RowsAffected: 2, 3101 Info: plan.UpdateInfo{ 3102 Matched: 2, 3103 Updated: 2, 3104 }, 3105 }}}, 3106 }, 3107 { 3108 Query: "SELECT base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 3109 Expected: []sql.Row{ 3110 {1, 1, 1, 300, 1, -100}, 3111 {2, 2, 2, 300, 2, -100}, 3112 }, 3113 }, 3114 }, 3115 }, 3116 { 3117 Name: "conflicts of different schemas can't coexist", 3118 SetUpScript: []string{ 3119 "SET dolt_allow_commit_conflicts = on", 3120 "CREATE table t (pk int PRIMARY KEY, col1 int);", 3121 "CALL DOLT_ADD('.')", 3122 "CALL DOLT_COMMIT('-am', 'create table');", 3123 "INSERT INTO t VALUES (1, 1);", 3124 "CALL DOLT_COMMIT('-am', 'insert pk 1');", 3125 3126 "CALL DOLT_BRANCH('other');", 3127 "UPDATE t set col1 = 100 where pk = 1;", 3128 "CALL DOLT_COMMIT('-am', 'left edit');", 3129 "CALL DOLT_CHECKOUT('other');", 3130 3131 "UPDATE T set col1 = -100 where pk = 1;", 3132 "CALL DOLT_COMMIT('-am', 'right edit');", 3133 "CALL DOLT_CHECKOUT('main');", 3134 "CALL DOLT_MERGE('other');", 3135 "CALL DOLT_COMMIT('-afm', 'commit conflicts on main');", 3136 "ALTER TABLE t ADD COLUMN col2 int;", 3137 "CALL DOLT_COMMIT('-afm', 'alter schema');", 3138 "CALL DOLT_CHECKOUT('-b', 'other2');", 3139 "UPDATE t set col2 = -1000 where pk = 1;", 3140 "CALL DOLT_COMMIT('-afm', 'update pk 1 to -1000');", 3141 "CALL DOLT_CHECKOUT('main');", 3142 "UPDATE t set col2 = 1000 where pk = 1;", 3143 "CALL DOLT_COMMIT('-afm', 'update pk 1 to 1000');", 3144 }, 3145 Assertions: []queries.ScriptTestAssertion{ 3146 { 3147 Query: "CALL DOLT_MERGE('other2');", 3148 ExpectedErrStr: "the existing conflicts are of a different schema than the conflicts generated by this merge. Please resolve them and try again", 3149 }, 3150 { 3151 Query: "SELECT base_pk, base_col1, our_pk, our_col1, their_pk, their_col1 from dolt_conflicts_t;", 3152 Expected: []sql.Row{{1, 1, 1, 100, 1, -100}}, 3153 }, 3154 { 3155 Query: "SELECT pk, col1, col2 from t;", 3156 Expected: []sql.Row{{1, 100, 1000}}, 3157 }, 3158 }, 3159 }, 3160 { 3161 Name: "violations with an older commit hash are overwritten if the value is the same", 3162 SetUpScript: []string{ 3163 "set dolt_force_transaction_commit = on;", 3164 3165 "CALL DOLT_CHECKOUT('-b', 'viol1');", 3166 "CREATE TABLE parent (pk int PRIMARY KEY);", 3167 "CREATE TABLE child (pk int PRIMARY KEY, fk int, FOREIGN KEY (fk) REFERENCES parent (pk));", 3168 "CALL DOLT_ADD('.')", 3169 "CALL DOLT_COMMIT('-am', 'setup table');", 3170 "CALL DOLT_BRANCH('viol2');", 3171 "CALL DOLT_BRANCH('other3');", 3172 "INSERT INTO parent VALUES (1);", 3173 "CALL DOLT_COMMIT('-am', 'viol1 setup');", 3174 3175 "CALL DOLT_CHECKOUT('-b', 'other');", 3176 "INSERT INTO child VALUES (1, 1);", 3177 "CALL DOLT_COMMIT('-am', 'insert child of 1');", 3178 3179 "CALL DOLT_CHECKOUT('viol1');", 3180 "DELETE FROM parent where pk = 1;", 3181 "CALL DOLT_COMMIT('-am', 'delete 1');", 3182 "CALL DOLT_MERGE('other');", 3183 "CALL DOLT_COMMIT('-afm', 'commit violations 1');", 3184 3185 "CALL DOLT_CHECKOUT('viol2');", 3186 "INSERT INTO parent values (2);", 3187 "CALL DOLT_COMMIT('-am', 'viol2 setup');", 3188 3189 "CALL DOLT_CHECKOUT('-b', 'other2');", 3190 "INSERT into child values (2, 2);", 3191 "CALL DOLT_COMMIT('-am', 'insert child of 2');", 3192 3193 "CALL DOLT_CHECKOUT('viol2');", 3194 "DELETE FROM parent where pk = 2;", 3195 "CALL DOLT_COMMIT('-am', 'delete 2');", 3196 "CALL DOLT_MERGE('other2');", 3197 "CALL DOLT_COMMIT('-afm', 'commit violations 2');", 3198 3199 "CALL DOLT_CHECKOUT('other3');", 3200 "INSERT INTO PARENT VALUES (3);", 3201 "CALL DOLT_COMMIT('-am', 'edit needed to trigger three-way merge');", 3202 3203 "CALL DOLT_CHECKOUT('viol1');", 3204 }, 3205 Assertions: []queries.ScriptTestAssertion{ 3206 { 3207 Query: "SELECT violation_type, pk, fk from dolt_constraint_violations_child;", 3208 Expected: []sql.Row{{"foreign key", 1, 1}}, 3209 }, 3210 { 3211 Query: "SELECT pk, fk from child;", 3212 Expected: []sql.Row{{1, 1}}, 3213 }, 3214 { 3215 Query: "SELECT * from parent;", 3216 Expected: []sql.Row{}, 3217 }, 3218 { 3219 Query: "CALL DOLT_CHECKOUT('viol2');", 3220 Expected: []sql.Row{{0, "Switched to branch 'viol2'"}}, 3221 }, 3222 { 3223 Query: "SELECT violation_type, pk, fk from dolt_constraint_violations_child;", 3224 Expected: []sql.Row{{"foreign key", 2, 2}}, 3225 }, 3226 { 3227 Query: "SELECT pk, fk from child;", 3228 Expected: []sql.Row{{2, 2}}, 3229 }, 3230 { 3231 Query: "SELECT * from parent;", 3232 Expected: []sql.Row{}, 3233 }, 3234 { 3235 Query: "CALL DOLT_MERGE('viol1');", 3236 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3237 }, 3238 // the commit hashes for the above two violations change in this merge 3239 { 3240 Query: "SELECT violation_type, fk, pk from dolt_constraint_violations_child;", 3241 Expected: []sql.Row{{"foreign key", 1, 1}, {"foreign key", 2, 2}}, 3242 }, 3243 { 3244 Query: "SELECT pk, fk from child;", 3245 Expected: []sql.Row{{1, 1}, {2, 2}}, 3246 }, 3247 { 3248 Query: "SELECT * from parent;", 3249 Expected: []sql.Row{}, 3250 }, 3251 { 3252 Query: "CALL DOLT_COMMIT('-afm', 'commit active merge');", 3253 Expected: []sql.Row{{doltCommit}}, 3254 }, 3255 { 3256 Query: "SET FOREIGN_KEY_CHECKS=0;", 3257 Expected: []sql.Row{{}}, 3258 }, 3259 { 3260 Query: "UPDATE child set fk = 4;", 3261 Expected: []sql.Row{{types.OkResult{RowsAffected: 2, InsertID: 0, Info: plan.UpdateInfo{Matched: 2, Updated: 2}}}}, 3262 }, 3263 { 3264 Query: "CALL DOLT_COMMIT('-afm', 'update children to new value');", 3265 Expected: []sql.Row{{doltCommit}}, 3266 }, 3267 { 3268 Query: "CALL DOLT_MERGE('other3');", 3269 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3270 }, 3271 { 3272 Query: "SELECT violation_type, pk, fk from dolt_constraint_violations_child;", 3273 Expected: []sql.Row{ 3274 {"foreign key", 1, 1}, 3275 {"foreign key", 1, 4}, 3276 {"foreign key", 2, 2}, 3277 {"foreign key", 2, 4}}, 3278 }, 3279 }, 3280 }, 3281 { 3282 Name: "merging unique key violations in left and right", 3283 SetUpScript: []string{ 3284 "SET dolt_force_transaction_commit = on;", 3285 "CREATE TABLE t (pk int PRIMARY KEY, col1 int UNIQUE);", 3286 "CALL DOLT_ADD('.')", 3287 "CALL DOLT_COMMIT('-am', 'create table t');", 3288 "CALL DOLT_BRANCH('right');", 3289 "CALL DOLT_BRANCH('left2');", 3290 3291 "CALL DOLT_CHECKOUT('-b', 'right2');", 3292 "INSERT INTO T VALUES (4, 1);", 3293 "CALL DOLT_COMMIT('-am', 'right2 insert');", 3294 3295 "CALL DOLT_CHECKOUT('right');", 3296 "INSERT INTO T VALUES (3, 1);", 3297 "CALL DOLT_COMMIT('-am', 'right insert');", 3298 3299 "CALL DOLT_CHECKOUT('left2');", 3300 "INSERT INTO T VALUES (2, 1);", 3301 "CALL DOLT_COMMIT('-am', 'left2 insert');", 3302 3303 "CALL DOLT_CHECKOUT('main');", 3304 "INSERT INTO T VALUES (1, 1);", 3305 "CALL DOLT_COMMIT('-am', 'left insert');", 3306 }, 3307 Assertions: []queries.ScriptTestAssertion{ 3308 { 3309 Query: "CALL DOLT_MERGE('left2');", 3310 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3311 }, 3312 { 3313 Query: "SELECT * from t;", 3314 Expected: []sql.Row{{1, 1}, {2, 1}}, 3315 }, 3316 { 3317 Query: "SELECT violation_type, pk, col1 from dolt_constraint_violations_t;", 3318 Expected: []sql.Row{{"unique index", 1, 1}, {"unique index", 2, 1}}, 3319 }, 3320 { 3321 Query: "CALL DOLT_COMMIT('-afm', 'commit unique key viol');", 3322 Expected: []sql.Row{{doltCommit}}, 3323 }, 3324 { 3325 Query: "CALL DOLT_CHECKOUT('right');", 3326 Expected: []sql.Row{{0, "Switched to branch 'right'"}}, 3327 }, 3328 { 3329 Query: "CALL DOLT_MERGE('right2');", 3330 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3331 }, 3332 { 3333 Query: "SELECT * from t;", 3334 Expected: []sql.Row{{3, 1}, {4, 1}}, 3335 }, 3336 { 3337 Query: "SELECT violation_type, pk, col1 from dolt_constraint_violations_t;", 3338 Expected: []sql.Row{{"unique index", 3, 1}, {"unique index", 4, 1}}, 3339 }, 3340 { 3341 Query: "CALL DOLT_COMMIT('-afm', 'commit unique key viol');", 3342 Expected: []sql.Row{{doltCommit}}, 3343 }, 3344 { 3345 Query: "CALL DOLT_CHECKOUT('main');", 3346 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 3347 }, 3348 { 3349 Query: "CALL DOLT_MERGE('right');", 3350 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3351 }, 3352 { 3353 Query: "SELECT * from t;", 3354 Expected: []sql.Row{{1, 1}, {2, 1}, {3, 1}, {4, 1}}, 3355 }, 3356 { 3357 Query: "SELECT violation_type, pk, col1 from dolt_constraint_violations_t;", 3358 Expected: []sql.Row{ 3359 {"unique index", 1, 1}, 3360 {"unique index", 2, 1}, 3361 {"unique index", 3, 1}, 3362 {"unique index", 4, 1}}, 3363 }, 3364 }, 3365 }, 3366 { 3367 Name: "right adds a unique key constraint and resolves existing violations.", 3368 SetUpScript: []string{ 3369 "SET dolt_force_transaction_commit = on;", 3370 "CREATE TABLE t (pk int PRIMARY KEY, col1 int);", 3371 "CALL DOLT_ADD('.')", 3372 "INSERT INTO t VALUES (1, 1), (2, 1);", 3373 "CALL DOLT_COMMIT('-am', 'table and data');", 3374 3375 "CALL DOLT_CHECKOUT('-b', 'right');", 3376 "UPDATE t SET col1 = 2 where pk = 2;", 3377 "ALTER TABLE t ADD UNIQUE col1_uniq (col1);", 3378 "CALL DOLT_COMMIT('-am', 'right adds a unique index');", 3379 3380 "CALL DOLT_CHECKOUT('main');", 3381 "INSERT INTO t VALUES (3, 3);", 3382 "CALL DOLT_COMMIT('-am', 'left edit');", 3383 }, 3384 Assertions: []queries.ScriptTestAssertion{ 3385 { 3386 Query: "CALL DOLT_MERGE('right');", 3387 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 3388 }, 3389 { 3390 Query: "SELECT * from t;", 3391 Expected: []sql.Row{{1, 1}, {2, 2}, {3, 3}}, 3392 }, 3393 }, 3394 }, 3395 { 3396 Name: "unique key violation should be thrown even if a PK column is used in the unique index", 3397 SetUpScript: []string{ 3398 "create table t (col1 int not null, col2 int not null, col3 int, primary key (col1, col2));", 3399 "alter table t add unique (col2, col3);", 3400 "call dolt_commit('-Am', 'init');", 3401 3402 "call dolt_checkout('-b', 'right');", 3403 "insert into t values (1, 2, 3);", 3404 "call dolt_commit('-Am', 'right');", 3405 3406 "call dolt_checkout('main');", 3407 "insert into t values (2, 2, 3);", 3408 "call dolt_commit('-Am', 'left');", 3409 3410 "set dolt_force_transaction_commit = 1;", 3411 }, 3412 Assertions: []queries.ScriptTestAssertion{ 3413 { 3414 Query: "call dolt_merge('right');", 3415 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3416 }, 3417 { 3418 Query: "select col1, col2, col3 from dolt_constraint_violations_t;", 3419 Expected: []sql.Row{{1, 2, 3}, {2, 2, 3}}, 3420 }, 3421 }, 3422 }, 3423 { 3424 Name: "unique key violation should be thrown even if a PK column is used in the unique index 2", 3425 SetUpScript: []string{ 3426 "create table wxyz (w int, x int, y int, z int, primary key (x, w));", 3427 "alter table wxyz add unique (z, x);", 3428 "call dolt_commit('-Am', 'init');", 3429 3430 "call dolt_checkout('-b', 'right');", 3431 "insert into wxyz values (1, 2, 3, 4);", 3432 "call dolt_commit('-Am', 'right');", 3433 3434 "call dolt_checkout('main');", 3435 "insert into wxyz values (5, 2, 6, 4);", 3436 "call dolt_commit('-Am', 'left');", 3437 3438 "set dolt_force_transaction_commit = 1;", 3439 }, 3440 Assertions: []queries.ScriptTestAssertion{ 3441 { 3442 Query: "call dolt_merge('right');", 3443 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3444 }, 3445 { 3446 Query: "select w, x, y, z from dolt_constraint_violations_wxyz;", 3447 Expected: []sql.Row{{1, 2, 3, 4}, {5, 2, 6, 4}}, 3448 }, 3449 }, 3450 }, 3451 { 3452 Name: "unique key violations should not be thrown for keys with null values", 3453 SetUpScript: []string{ 3454 "create table t (col1 int not null, col2 int not null, col3 int, primary key (col1, col2));", 3455 "alter table t add unique (col2, col3);", 3456 "call dolt_commit('-Am', 'init');", 3457 3458 "call dolt_checkout('-b', 'right');", 3459 "insert into t values (1, 2, null);", 3460 "call dolt_commit('-Am', 'right');", 3461 3462 "call dolt_checkout('main');", 3463 "insert into t values (2, 2, null);", 3464 "call dolt_commit('-Am', 'left');", 3465 3466 "set dolt_force_transaction_commit = 1;", 3467 }, 3468 Assertions: []queries.ScriptTestAssertion{ 3469 { 3470 Query: "call dolt_merge('right');", 3471 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 3472 }, 3473 { 3474 Query: "select count(*) from dolt_constraint_violations;", 3475 Expected: []sql.Row{{0}}, 3476 }, 3477 { 3478 Query: "select * from t;", 3479 Expected: []sql.Row{{1, 2, nil}, {2, 2, nil}}, 3480 }, 3481 }, 3482 }, 3483 { 3484 Name: "regression test for bad column ordering in schema", 3485 SetUpScript: []string{ 3486 "CREATE TABLE t (col1 enum ('A', 'B'), col2 varchar(100), primary key (col2));", 3487 "ALTER TABLE t add unique index (col1);", 3488 "call DOLT_COMMIT('-Am', 'initial');", 3489 3490 "call DOLT_CHECKOUT('-b', 'right');", 3491 "insert into t values ('A', 'first');", 3492 "call DOLT_COMMIT('-Am', 'right');", 3493 3494 "call DOLT_CHECKOUT('main');", 3495 "insert into t values ('A', 'second');", 3496 "call DOLT_COMMIT('-Am', 'left');", 3497 3498 "set dolt_force_transaction_commit = 1;", 3499 }, 3500 Assertions: []queries.ScriptTestAssertion{ 3501 { 3502 Query: "call dolt_merge('right');", 3503 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3504 }, 3505 { 3506 Query: "select col1, col2 from dolt_constraint_violations_t;", 3507 Expected: []sql.Row{{"A", "first"}, {"A", "second"}}, 3508 }, 3509 }, 3510 }, 3511 { 3512 Name: "Multiple foreign key violations for a given row not supported", 3513 SetUpScript: []string{ 3514 "SET dolt_force_transaction_commit = on;", 3515 ` 3516 CREATE TABLE parent( 3517 pk int PRIMARY KEY, 3518 col1 int, 3519 col2 int, 3520 INDEX par_col1_idx (col1), 3521 INDEX par_col2_idx (col2) 3522 );`, 3523 ` 3524 CREATE TABLE child( 3525 pk int PRIMARY KEY, 3526 col1 int, 3527 col2 int, 3528 FOREIGN KEY (col1) REFERENCES parent(col1), 3529 FOREIGN KEY (col2) REFERENCES parent(col2) 3530 );`, 3531 "CALL DOLT_ADD('.')", 3532 "INSERT INTO parent VALUES (1, 1, 1);", 3533 "CALL DOLT_COMMIT('-am', 'initial');", 3534 3535 "CALL DOLT_CHECKOUT('-b', 'right');", 3536 "INSERT INTO CHILD VALUES (1, 1, 1);", 3537 "CALL DOLT_COMMIT('-am', 'insert child');", 3538 3539 "CALL DOLT_CHECKOUT('main');", 3540 "DELETE from parent where pk = 1;", 3541 "CALL DOLT_COMMIT('-am', 'delete parent');", 3542 }, 3543 Assertions: []queries.ScriptTestAssertion{ 3544 { 3545 Query: "CALL DOLT_MERGE('right');", 3546 ExpectedErrStr: "error storing constraint violation for primary key (( 1 )): another violation already exists\nnew violation: {\"Columns\":[\"col1\"],\"ForeignKey\":\"child_ibfk_1\",\"Index\":\"col1\",\"OnDelete\":\"RESTRICT\",\"OnUpdate\":\"RESTRICT\",\"ReferencedColumns\":[\"col1\"],\"ReferencedIndex\":\"par_col1_idx\",\"ReferencedTable\":\"parent\",\"Table\":\"child\"} old violation: ({\"Columns\":[\"col2\"],\"ForeignKey\":\"child_ibfk_2\",\"Index\":\"col2\",\"OnDelete\":\"RESTRICT\",\"OnUpdate\":\"RESTRICT\",\"ReferencedColumns\":[\"col2\"],\"ReferencedIndex\":\"par_col2_idx\",\"ReferencedTable\":\"parent\",\"Table\":\"child\"})", 3547 }, 3548 { 3549 Query: "SELECT * from parent;", 3550 Expected: []sql.Row{}, 3551 }, 3552 { 3553 Query: "SELECT * from child;", 3554 Expected: []sql.Row{}, 3555 }, 3556 }, 3557 }, 3558 { 3559 Name: "Multiple unique key violations for a given row not supported", 3560 SetUpScript: []string{ 3561 "SET dolt_force_transaction_commit = on;", 3562 "CREATE table t (pk int PRIMARY KEY, col1 int UNIQUE, col2 int UNIQUE);", 3563 "CALL DOLT_ADD('.')", 3564 "CALL DOLT_COMMIT('-am', 'setup');", 3565 3566 "CALL DOLT_CHECKOUT('-b', 'right');", 3567 "INSERT into t VALUES (2, 1, 1);", 3568 "CALL DOLT_COMMIT('-am', 'right insert');", 3569 3570 "CALL DOLT_CHECKOUT('main');", 3571 "INSERT INTO t VALUES (1, 1, 1);", 3572 "CALL DOLT_COMMIT('-am', 'left insert');", 3573 }, 3574 Assertions: []queries.ScriptTestAssertion{ 3575 { 3576 Query: "CALL DOLT_MERGE('right');", 3577 ExpectedErrStr: "error storing constraint violation for primary key (( 1 )): another violation already exists\nnew violation: {\"Columns\":[\"col1\"],\"Name\":\"col1\"} old violation: ({\"Columns\":[\"col2\"],\"Name\":\"col2\"})", 3578 }, 3579 { 3580 Query: "SELECT * from t;", 3581 Expected: []sql.Row{{1, 1, 1}}, 3582 }, 3583 }, 3584 }, 3585 { 3586 Name: "Multiple unique key violations part 1 (repro issue #5719)", 3587 SetUpScript: []string{ 3588 "SET dolt_force_transaction_commit = on;", 3589 "CREATE TABLE t (id int NOT NULL, col1 varchar(255), col2 varchar(255), col3 varchar(255), PRIMARY KEY (id), UNIQUE KEY uniq_idx (col1,col2,col3));", 3590 "CALL DOLT_ADD('.')", 3591 "CALL DOLT_COMMIT('-am', 'setup');", 3592 3593 "CALL DOLT_CHECKOUT('-b', 'right');", 3594 "INSERT INTO t (id, col1, col2, col3) VALUES (1, 'val1', 'val1', 'val1'), (4, 'val1', 'val1', 'val2')", 3595 "CALL DOLT_COMMIT('-am', 'right insert');", 3596 3597 "CALL DOLT_CHECKOUT('main');", 3598 "INSERT INTO t (id, col1, col2, col3) VALUES (2, 'val1', 'val1', 'val1'), (3, 'val1', 'val1', 'val2');", 3599 "CALL DOLT_COMMIT('-am', 'left insert');", 3600 }, 3601 Assertions: []queries.ScriptTestAssertion{ 3602 { 3603 Query: "CALL DOLT_MERGE('right');", 3604 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3605 }, 3606 { 3607 Query: "select * from dolt_constraint_violations;", 3608 Expected: []sql.Row{{"t", uint64(4)}}, 3609 }, 3610 { 3611 Query: "select id, col1, col2, col3 from dolt_constraint_violations_t;", 3612 Expected: []sql.Row{ 3613 {1, "val1", "val1", "val1"}, 3614 {2, "val1", "val1", "val1"}, 3615 {3, "val1", "val1", "val2"}, 3616 {4, "val1", "val1", "val2"}, 3617 }, 3618 }, 3619 }, 3620 }, 3621 { 3622 Name: "Multiple unique key violations part 2 (repro issue #5719)", 3623 SetUpScript: []string{ 3624 "SET dolt_force_transaction_commit = on;", 3625 "CREATE TABLE t (id int NOT NULL, col1 varchar(255), col2 varchar(255), col3 varchar(255), PRIMARY KEY (id), UNIQUE KEY uniq_idx (col1,col2,col3));", 3626 "INSERT INTO t (id, col1, col2, col3) VALUES (1, 'val1', 'val1', 'val1'), (2, 'val1', 'val2', 'val1')", 3627 "CALL DOLT_ADD('.')", 3628 "CALL DOLT_COMMIT('-am', 'new table');", 3629 3630 "CALL DOLT_CHECKOUT('-b', 'right');", 3631 "UPDATE t SET col3 = 'val2'", 3632 "CALL DOLT_COMMIT('-am', 'right update');", 3633 3634 "CALL DOLT_CHECKOUT('main');", 3635 "INSERT INTO t (id, col1, col2, col3) VALUES (3, 'val1', 'val1', 'val2');", 3636 "CALL DOLT_COMMIT('-am', 'main insert');", 3637 }, 3638 Assertions: []queries.ScriptTestAssertion{ 3639 { 3640 Query: "CALL DOLT_MERGE('right');", 3641 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3642 }, 3643 { 3644 Query: "select * from dolt_constraint_violations;", 3645 Expected: []sql.Row{{"t", uint64(2)}}, 3646 }, 3647 { 3648 Query: "select id, col1, col2, col3 from dolt_constraint_violations_t;", 3649 Expected: []sql.Row{ 3650 {1, "val1", "val1", "val2"}, 3651 {3, "val1", "val1", "val2"}, 3652 }, 3653 }, 3654 }, 3655 }, 3656 { 3657 Name: "Multiple unique key violations part 3 (repro issue #5719)", 3658 SetUpScript: []string{ 3659 "SET dolt_force_transaction_commit = on;", 3660 "CREATE TABLE t (id int NOT NULL, col1 varchar(255), col2 varchar(255), col3 varchar(255), PRIMARY KEY (id), UNIQUE KEY uniq_idx (col1,col2,col3));", 3661 "INSERT INTO t (id, col1, col2, col3) VALUES (1, 'val1', 'val1', 'val1'), (4, 'val1', 'val2', 'val1')", 3662 "CALL DOLT_ADD('.')", 3663 "CALL DOLT_COMMIT('-am', 'new table');", 3664 3665 "CALL DOLT_CHECKOUT('-b', 'right');", 3666 "UPDATE t SET col3 = 'val2'", 3667 "CALL DOLT_COMMIT('-am', 'right update');", 3668 3669 "CALL DOLT_CHECKOUT('main');", 3670 "INSERT INTO t (id, col1, col2, col3) VALUES (3, 'val1', 'val1', 'val2');", 3671 "CALL DOLT_COMMIT('-am', 'main insert');", 3672 "CALL DOLT_CHECKOUT('right');", 3673 }, 3674 Assertions: []queries.ScriptTestAssertion{ 3675 { 3676 Query: "CALL DOLT_MERGE('main');", 3677 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3678 }, 3679 { 3680 Query: "select * from dolt_constraint_violations;", 3681 Expected: []sql.Row{{"t", uint64(2)}}, 3682 }, 3683 { 3684 Query: "select id, col1, col2, col3 from dolt_constraint_violations_t;", 3685 Expected: []sql.Row{ 3686 {1, "val1", "val1", "val2"}, 3687 {3, "val1", "val1", "val2"}, 3688 }, 3689 }, 3690 }, 3691 }, 3692 } 3693 3694 var SchemaConflictScripts = []queries.ScriptTest{ 3695 { 3696 Name: "schema conflicts return an error when autocommit is enabled", 3697 SetUpScript: []string{ 3698 "set @@autocommit=1;", 3699 "create table t (pk int primary key, c0 varchar(20))", 3700 "call dolt_commit('-Am', 'added tabele t')", 3701 "call dolt_checkout('-b', 'other')", 3702 "alter table t modify column c0 int", 3703 "call dolt_commit('-am', 'altered t on branch other')", 3704 "call dolt_checkout('main')", 3705 "alter table t modify column c0 datetime(6)", 3706 "call dolt_commit('-am', 'altered t on branch main')", 3707 }, 3708 Assertions: []queries.ScriptTestAssertion{ 3709 { 3710 Query: "call dolt_merge('other')", 3711 ExpectedErrStr: dsess.ErrUnresolvedConflictsAutoCommit.Error(), 3712 }, 3713 { 3714 Query: "select * from dolt_schema_conflicts", 3715 Expected: []sql.Row{}, 3716 }, 3717 { 3718 Query: "select * from dolt_status", 3719 Expected: []sql.Row{}, 3720 }, 3721 }, 3722 }, 3723 { 3724 Name: "divergent type change causes schema conflict", 3725 SetUpScript: []string{ 3726 "set @@autocommit=0;", 3727 "create table t (pk int primary key, c0 varchar(20))", 3728 "call dolt_commit('-Am', 'added tabele t')", 3729 "call dolt_checkout('-b', 'other')", 3730 "alter table t modify column c0 int", 3731 "call dolt_commit('-am', 'altered t on branch other')", 3732 "call dolt_checkout('main')", 3733 "alter table t modify column c0 datetime(6)", 3734 "call dolt_commit('-am', 'altered t on branch main')", 3735 }, 3736 Assertions: []queries.ScriptTestAssertion{ 3737 { 3738 Query: "call dolt_merge('other')", 3739 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3740 }, 3741 { 3742 Query: "select * from dolt_schema_conflicts", 3743 Expected: []sql.Row{{ 3744 "t", 3745 "CREATE TABLE `t` (\n `pk` int NOT NULL,\n `c0` varchar(20),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", 3746 "CREATE TABLE `t` (\n `pk` int NOT NULL,\n `c0` datetime(6),\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", 3747 "CREATE TABLE `t` (\n `pk` int NOT NULL,\n `c0` int,\n PRIMARY KEY (`pk`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", 3748 "different column definitions for our column c0 and their column c0", 3749 }}, 3750 }, 3751 { 3752 Query: "select * from dolt_status", 3753 Expected: []sql.Row{ 3754 {"t", false, "schema conflict"}, 3755 }, 3756 }, 3757 }, 3758 }, 3759 } 3760 3761 // OldFormatMergeConflictsAndCVsScripts tests old format merge behavior 3762 // where violations are appended and merges are aborted if there are existing 3763 // violations and/or conflicts. 3764 var OldFormatMergeConflictsAndCVsScripts = []queries.ScriptTest{ 3765 { 3766 Name: "merging branches into a constraint violated head. Any new violations are appended", 3767 SetUpScript: []string{ 3768 "CREATE table parent (pk int PRIMARY KEY, col1 int);", 3769 "CREATE table child (pk int PRIMARY KEY, parent_fk int, FOREIGN KEY (parent_fk) REFERENCES parent(pk));", 3770 "CREATE table other (pk int);", 3771 "CALL DOLT_ADD('.')", 3772 "INSERT INTO parent VALUES (1, 1), (2, 2);", 3773 "CALL DOLT_COMMIT('-am', 'setup');", 3774 "CALL DOLT_BRANCH('branch1');", 3775 "CALL DOLT_BRANCH('branch2');", 3776 }, 3777 Assertions: []queries.ScriptTestAssertion{ 3778 { 3779 // we need dolt_force_transaction_commit because we want to 3780 // transaction commit constraint violations that occur as a 3781 // result of a merge. 3782 Query: "set autocommit = off, dolt_force_transaction_commit = on", 3783 Expected: []sql.Row{{}}, 3784 }, 3785 { 3786 Query: "DELETE FROM parent where pk = 1;", 3787 Expected: []sql.Row{{types.NewOkResult(1)}}, 3788 }, 3789 { 3790 Query: "CALL DOLT_COMMIT('-am', 'delete parent 1');", 3791 Expected: []sql.Row{{doltCommit}}, 3792 }, 3793 { 3794 Query: "CALL DOLT_CHECKOUT('branch1');", 3795 Expected: []sql.Row{{0, "Switched to branch 'branch1'"}}, 3796 }, 3797 { 3798 Query: "INSERT INTO CHILD VALUES (1, 1);", 3799 Expected: []sql.Row{{types.NewOkResult(1)}}, 3800 }, 3801 { 3802 Query: "CALL DOLT_COMMIT('-am', 'insert child of parent 1');", 3803 Expected: []sql.Row{{doltCommit}}, 3804 }, 3805 { 3806 Query: "CALL DOLT_CHECKOUT('main');", 3807 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 3808 }, 3809 { 3810 Query: "CALL DOLT_MERGE('branch1');", 3811 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3812 }, 3813 { 3814 Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;", 3815 Expected: []sql.Row{{uint16(1), 1, 1}}, 3816 }, 3817 { 3818 Query: "COMMIT;", 3819 Expected: []sql.Row{}, 3820 }, 3821 { 3822 Query: "CALL DOLT_COMMIT('-am', 'commit constraint violations');", 3823 ExpectedErrStr: "error: the table(s) child have constraint violations", 3824 }, 3825 { 3826 Query: "CALL DOLT_COMMIT('-afm', 'commit constraint violations');", 3827 Expected: []sql.Row{{doltCommit}}, 3828 }, 3829 { 3830 Query: "CALL DOLT_BRANCH('branch3');", 3831 Expected: []sql.Row{{0}}, 3832 }, 3833 { 3834 Query: "DELETE FROM parent where pk = 2;", 3835 Expected: []sql.Row{{types.NewOkResult(1)}}, 3836 }, 3837 { 3838 Query: "CALL DOLT_COMMIT('-afm', 'remove parent 2');", 3839 Expected: []sql.Row{{doltCommit}}, 3840 }, 3841 { 3842 Query: "CALL DOLT_CHECKOUT('branch2');", 3843 Expected: []sql.Row{{0, "Switched to branch 'branch2'"}}, 3844 }, 3845 { 3846 Query: "INSERT INTO OTHER VALUES (1);", 3847 Expected: []sql.Row{{types.NewOkResult(1)}}, 3848 }, 3849 { 3850 Query: "CALL DOLT_COMMIT('-am', 'non-fk insert');", 3851 Expected: []sql.Row{{doltCommit}}, 3852 }, 3853 { 3854 Query: "CALL DOLT_CHECKOUT('main');", 3855 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 3856 }, 3857 { 3858 Query: "CALL DOLT_MERGE('branch2');", 3859 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3860 }, 3861 { 3862 Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;", 3863 Expected: []sql.Row{{uint16(1), 1, 1}}, 3864 }, 3865 { 3866 Query: "COMMIT;", 3867 Expected: []sql.Row{}, 3868 }, 3869 { 3870 Query: "CALL DOLT_COMMIT('-am', 'commit non-conflicting merge');", 3871 ExpectedErrStr: "error: the table(s) child have constraint violations", 3872 }, 3873 { 3874 Query: "CALL DOLT_COMMIT('-afm', 'commit non-conflicting merge');", 3875 Expected: []sql.Row{{doltCommit}}, 3876 }, 3877 { 3878 Query: "CALL DOLT_CHECKOUT('branch3');", 3879 Expected: []sql.Row{{0, "Switched to branch 'branch3'"}}, 3880 }, 3881 { 3882 Query: "INSERT INTO CHILD VALUES (2, 2);", 3883 Expected: []sql.Row{{types.NewOkResult(1)}}, 3884 }, 3885 { 3886 Query: "CALL DOLT_COMMIT('-afm', 'add child of parent 2');", 3887 Expected: []sql.Row{{doltCommit}}, 3888 }, 3889 { 3890 Query: "CALL DOLT_CHECKOUT('main');", 3891 Expected: []sql.Row{{0, "Switched to branch 'main'"}}, 3892 }, 3893 { 3894 Query: "CALL DOLT_MERGE('branch3');", 3895 Expected: []sql.Row{{"", 0, 1, "conficts found"}}, 3896 }, 3897 { 3898 Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;", 3899 Expected: []sql.Row{{uint16(1), 1, 1}, {uint16(1), 2, 2}}, 3900 }, 3901 }, 3902 }, 3903 { 3904 Name: "conflicting merge aborts when conflicts and violations already exist", 3905 SetUpScript: []string{ 3906 "CREATE table parent (pk int PRIMARY KEY, col1 int);", 3907 "CREATE table child (pk int PRIMARY KEY, parent_fk int, FOREIGN KEY (parent_fk) REFERENCES parent(pk));", 3908 "CALL DOLT_ADD('.')", 3909 "INSERT INTO parent VALUES (1, 1), (2, 1);", 3910 "CALL DOLT_COMMIT('-am', 'create table with data');", 3911 "CALL DOLT_BRANCH('other');", 3912 "CALL DOLT_BRANCH('other2');", 3913 "UPDATE parent SET col1 = 2 where pk = 1;", 3914 "DELETE FROM parent where pk = 2;", 3915 "CALL DOLT_COMMIT('-am', 'updating col1 to 2 and remove pk = 2');", 3916 "CALL DOLT_CHECKOUT('other');", 3917 "UPDATE parent SET col1 = 3 where pk = 1;", 3918 "INSERT into child VALUEs (1, 2);", 3919 "CALL DOLT_COMMIT('-am', 'updating col1 to 3 and adding child of pk 2');", 3920 "CALL DOLT_CHECKOUT('other2')", 3921 "UPDATE parent SET col1 = 4 where pk = 1", 3922 "CALL DOLT_COMMIT('-am', 'updating col1 to 4');", 3923 "CALL DOLT_CHECKOUT('main');", 3924 }, 3925 Assertions: []queries.ScriptTestAssertion{ 3926 { 3927 Query: "SET dolt_force_transaction_commit = 1", 3928 Expected: []sql.Row{{}}, 3929 }, 3930 { 3931 Query: "CALL DOLT_MERGE('other');", 3932 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 3933 }, 3934 { 3935 Query: "SELECT * from parent;", 3936 Expected: []sql.Row{{1, 2}}, 3937 }, 3938 { 3939 Query: "SELECT * from child;", 3940 Expected: []sql.Row{{1, 2}}, 3941 }, 3942 { 3943 Query: "SELECT base_col1, base_pk, our_col1, our_pk, their_col1, their_pk from dolt_conflicts_parent;", 3944 Expected: []sql.Row{{1, 1, 2, 1, 3, 1}}, 3945 }, 3946 { 3947 Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;", 3948 Expected: []sql.Row{{uint16(1), 1, 2}}, 3949 }, 3950 // commit so we can merge again 3951 { 3952 Query: "CALL DOLT_COMMIT('-afm', 'committing merge conflicts');", 3953 Expected: []sql.Row{{doltCommit}}, 3954 }, 3955 { 3956 Query: "CALL DOLT_MERGE('other2');", 3957 ExpectedErrStr: "existing unresolved conflicts would be overridden by new conflicts produced by merge. Please resolve them and try again", 3958 }, 3959 { 3960 Query: "SELECT * from parent;", 3961 Expected: []sql.Row{{1, 2}}, 3962 }, 3963 { 3964 Query: "SELECT * from child;", 3965 Expected: []sql.Row{{1, 2}}, 3966 }, 3967 { 3968 Query: "SELECT base_col1, base_pk, our_col1, our_pk, their_col1, their_pk from dolt_conflicts_parent;", 3969 Expected: []sql.Row{{1, 1, 2, 1, 3, 1}}, 3970 }, 3971 { 3972 Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;", 3973 Expected: []sql.Row{{uint16(1), 1, 2}}, 3974 }, 3975 }, 3976 }, 3977 { 3978 Name: "non-conflicting / non-violating merge succeeds when conflicts and violations already exist", 3979 SetUpScript: []string{ 3980 "CREATE table parent (pk int PRIMARY KEY, col1 int);", 3981 "CREATE table child (pk int PRIMARY KEY, parent_fk int, FOREIGN KEY (parent_fk) REFERENCES parent(pk));", 3982 "CALL DOLT_ADD('.')", 3983 "INSERT INTO parent VALUES (1, 1), (2, 1);", 3984 "CALL DOLT_COMMIT('-am', 'create table with data');", 3985 "CALL DOLT_BRANCH('other');", 3986 "CALL DOLT_BRANCH('other2');", 3987 "UPDATE parent SET col1 = 2 where pk = 1;", 3988 "DELETE FROM parent where pk = 2;", 3989 "CALL DOLT_COMMIT('-am', 'updating col1 to 2 and remove pk = 2');", 3990 "CALL DOLT_CHECKOUT('other');", 3991 "UPDATE parent SET col1 = 3 where pk = 1;", 3992 "INSERT into child VALUES (1, 2);", 3993 "CALL DOLT_COMMIT('-am', 'updating col1 to 3 and adding child of pk 2');", 3994 "CALL DOLT_CHECKOUT('other2')", 3995 "INSERT INTO parent values (3, 1);", 3996 "CALL DOLT_COMMIT('-am', 'insert parent with pk 3');", 3997 "CALL DOLT_CHECKOUT('main');", 3998 }, 3999 Assertions: []queries.ScriptTestAssertion{ 4000 { 4001 Query: "SET dolt_force_transaction_commit = 1;", 4002 Expected: []sql.Row{{}}, 4003 }, 4004 { 4005 Query: "CALL DOLT_MERGE('other');", 4006 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 4007 }, 4008 { 4009 Query: "SELECT * from parent;", 4010 Expected: []sql.Row{{1, 2}}, 4011 }, 4012 { 4013 Query: "SELECT * from child;", 4014 Expected: []sql.Row{{1, 2}}, 4015 }, 4016 { 4017 Query: "SELECT base_col1, base_pk, our_col1, our_pk, their_col1, their_pk from dolt_conflicts_parent;", 4018 Expected: []sql.Row{{1, 1, 2, 1, 3, 1}}, 4019 }, 4020 { 4021 Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;", 4022 Expected: []sql.Row{{uint16(1), 1, 2}}, 4023 }, 4024 // commit so we can merge again 4025 { 4026 Query: "CALL DOLT_COMMIT('-afm', 'committing merge conflicts');", 4027 Expected: []sql.Row{{doltCommit}}, 4028 }, 4029 { 4030 Query: "CALL DOLT_MERGE('other2');", 4031 Expected: []sql.Row{{"", 0, 1, "conflicts found"}}, 4032 }, 4033 { 4034 Query: "SELECT * from parent;", 4035 Expected: []sql.Row{{1, 2}, {3, 1}}, 4036 }, 4037 { 4038 Query: "SELECT * from child;", 4039 Expected: []sql.Row{{1, 2}}, 4040 }, 4041 { 4042 Query: "SELECT base_col1, base_pk, our_col1, our_pk, their_col1, their_pk from dolt_conflicts_parent;", 4043 Expected: []sql.Row{{1, 1, 2, 1, 3, 1}}, 4044 }, 4045 { 4046 Query: "SELECT violation_type, pk, parent_fk from dolt_constraint_violations_child;", 4047 Expected: []sql.Row{{uint16(1), 1, 2}}, 4048 }, 4049 }, 4050 }, 4051 // Unique key violations 4052 { 4053 Name: "unique key violations that already exist in the left abort the merge with an error", 4054 SetUpScript: []string{ 4055 "SET dolt_force_transaction_commit = on;", 4056 "CREATE TABLE t (pk int PRIMARY KEY, col1 int);", 4057 "CALL DOLT_ADD('.')", 4058 "CALL DOLT_COMMIT('-am', 'table');", 4059 "CALL DOLT_BRANCH('right');", 4060 "INSERT INTO t VALUES (1, 1), (2, 1);", 4061 "CALL DOLT_COMMIT('-am', 'data');", 4062 4063 "CALL DOLT_CHECKOUT('right');", 4064 "ALTER TABLE t ADD UNIQUE col1_uniq (col1);", 4065 "CALL DOLT_COMMIT('-am', 'unqiue constraint');", 4066 4067 "CALL DOLT_CHECKOUT('main');", 4068 }, 4069 Assertions: []queries.ScriptTestAssertion{ 4070 { 4071 Query: "CALL DOLT_MERGE('right');", 4072 ExpectedErrStr: "duplicate unique key given: [1]", 4073 }, 4074 { 4075 Query: "SELECT * from t", 4076 Expected: []sql.Row{{1, 1}, {2, 1}}, 4077 }, 4078 { 4079 Query: "show create table t", 4080 Expected: []sql.Row{{"t", 4081 "CREATE TABLE `t` (\n" + 4082 " `pk` int NOT NULL,\n" + 4083 " `col1` int,\n" + 4084 " PRIMARY KEY (`pk`)\n" + 4085 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}}, 4086 }, 4087 }, 4088 }, 4089 // not a base case, but helpful to understand... 4090 { 4091 Name: "right adds a unique key constraint and fixes existing violations. On merge, because left still has the violation, merge is aborted.", 4092 SetUpScript: []string{ 4093 "SET dolt_force_transaction_commit = on;", 4094 "CREATE TABLE t (pk int PRIMARY KEY, col1 int);", 4095 "CALL DOLT_ADD('.');", 4096 "INSERT INTO t VALUES (1, 1), (2, 1);", 4097 "CALL DOLT_COMMIT('-am', 'table and data');", 4098 4099 "CALL DOLT_CHECKOUT('-b', 'right');", 4100 "UPDATE t SET col1 = 2 where pk = 2;", 4101 "ALTER TABLE t ADD UNIQUE col1_uniq (col1);", 4102 "CALL DOLT_COMMIT('-am', 'right adds a unique index');", 4103 4104 "CALL DOLT_CHECKOUT('main');", 4105 "INSERT INTO t VALUES (3, 3);", 4106 "CALL DOLT_COMMIT('-am', 'left edit');", 4107 }, 4108 Assertions: []queries.ScriptTestAssertion{ 4109 { 4110 Query: "CALL DOLT_MERGE('right');", 4111 ExpectedErrStr: "duplicate unique key given: [1]", 4112 }, 4113 }, 4114 }, 4115 } 4116 4117 var GeneratedColumnMergeTestScripts = []queries.ScriptTest{ 4118 { 4119 Name: "merge a generated stored column", 4120 SetUpScript: []string{ 4121 "create table t1 (id bigint primary key, v1 bigint, v2 bigint, v3 bigint as (v1 + v2) stored, index (v3))", 4122 "insert into t1 (id, v1, v2) values (1, 1, 1), (2, 2, 2)", 4123 "call dolt_commit('-Am', 'first commit')", 4124 "call dolt_checkout('-b', 'branch1')", 4125 "insert into t1 (id, v1, v2) values (3, 3, 3)", 4126 "call dolt_commit('-Am', 'branch1 commit')", 4127 "call dolt_checkout('main')", 4128 "call dolt_checkout('-b', 'branch2')", 4129 "insert into t1 (id, v1, v2) values (4, 4, 4)", 4130 "call dolt_commit('-Am', 'branch2 commit')", 4131 "call dolt_checkout('main')", 4132 }, 4133 Assertions: []queries.ScriptTestAssertion{ 4134 { 4135 Query: "call dolt_merge('branch1')", 4136 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 4137 }, 4138 { 4139 Query: "select * from t1 order by id", 4140 Expected: []sql.Row{ 4141 {1, 1, 1, 2}, 4142 {2, 2, 2, 4}, 4143 {3, 3, 3, 6}, 4144 }, 4145 }, 4146 { 4147 Query: "select id from t1 where v3 = 6", 4148 Expected: []sql.Row{{3}}, 4149 }, 4150 { 4151 Query: "call dolt_merge('branch2')", 4152 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 4153 }, 4154 { 4155 Query: "select * from t1 order by id", 4156 Expected: []sql.Row{ 4157 {1, 1, 1, 2}, 4158 {2, 2, 2, 4}, 4159 {3, 3, 3, 6}, 4160 {4, 4, 4, 8}, 4161 }, 4162 }, 4163 { 4164 Query: "select id from t1 where v3 = 8", 4165 Expected: []sql.Row{{4}}, 4166 }, 4167 }, 4168 }, 4169 { 4170 Name: "merge a generated column with non-conflicting changes on both sides", 4171 SetUpScript: []string{ 4172 "create table t1 (id bigint primary key, v1 bigint, v2 bigint, v3 bigint as (v1 + v2) stored)", 4173 "insert into t1 (id, v1, v2) values (1, 1, 1), (2, 2, 2)", 4174 "call dolt_commit('-Am', 'first commit')", 4175 "call dolt_branch('branch1')", 4176 "call dolt_branch('branch2')", 4177 "call dolt_checkout('branch1')", 4178 "update t1 set v1 = 4 where id = 1", 4179 "call dolt_commit('-Am', 'branch1 commit')", 4180 "call dolt_checkout('branch2')", 4181 "update t1 set v2 = 5 where id = 1", 4182 "call dolt_commit('-Am', 'branch2 commit')", 4183 "call dolt_checkout('main')", 4184 }, 4185 Assertions: []queries.ScriptTestAssertion{ 4186 { 4187 Query: "call dolt_merge('branch1')", 4188 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 4189 }, 4190 { 4191 Query: "select * from t1 order by id", 4192 Expected: []sql.Row{ 4193 {1, 4, 1, 5}, 4194 {2, 2, 2, 4}, 4195 }, 4196 }, 4197 { 4198 Query: "select id from t1 where v3 = 5", 4199 Expected: []sql.Row{{1}}, 4200 }, 4201 { 4202 Query: "call dolt_merge('branch2')", 4203 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 4204 }, 4205 { 4206 Query: "select * from t1 order by id", 4207 Expected: []sql.Row{ 4208 {1, 4, 5, 9}, 4209 {2, 2, 2, 4}, 4210 }, 4211 }, 4212 { 4213 Query: "select id from t1 where v3 = 9", 4214 Expected: []sql.Row{{1}}, 4215 }, 4216 }, 4217 }, 4218 { 4219 Name: "merge a generated column created on another branch", 4220 SetUpScript: []string{ 4221 "create table t1 (id bigint primary key, v1 bigint, v2 bigint)", 4222 "insert into t1 (id, v1, v2) values (1, 1, 1), (2, 2, 2)", 4223 "call dolt_commit('-Am', 'first commit')", 4224 "call dolt_branch('branch1')", 4225 "insert into t1 (id, v1, v2) values (3, 3, 3)", 4226 "call dolt_commit('-Am', 'main commit')", 4227 "call dolt_checkout('branch1')", 4228 "alter table t1 add column v3 bigint as (v1 + v2) stored", 4229 "alter table t1 add key idx_v3 (v3)", 4230 "insert into t1 (id, v1, v2) values (4, 4, 4)", 4231 "call dolt_commit('-Am', 'branch1 commit')", 4232 "call dolt_checkout('main')", 4233 }, 4234 Assertions: []queries.ScriptTestAssertion{ 4235 { 4236 Query: "call dolt_merge('branch1')", 4237 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 4238 }, 4239 { 4240 Query: "select * from t1 order by id", 4241 Expected: []sql.Row{ 4242 {1, 1, 1, 2}, 4243 {2, 2, 2, 4}, 4244 {3, 3, 3, 6}, 4245 {4, 4, 4, 8}, 4246 }, 4247 }, 4248 { 4249 Query: "select id from t1 where v3 = 6", 4250 Expected: []sql.Row{{3}}, 4251 }, 4252 { 4253 Query: "select id from t1 where v3 = 8", 4254 Expected: []sql.Row{{4}}, 4255 }, 4256 }, 4257 }, 4258 { 4259 Name: "merge a virtual column", 4260 SetUpScript: []string{ 4261 "create table t1 (id bigint primary key, v1 bigint, v2 bigint, v3 bigint as (v1 + v2), index (v3))", 4262 "insert into t1 (id, v1, v2) values (1, 2, 3), (4, 5, 6)", 4263 "call dolt_commit('-Am', 'first commit')", 4264 "call dolt_checkout('-b', 'branch1')", 4265 "insert into t1 (id, v1, v2) values (7, 8, 9)", 4266 "call dolt_commit('-Am', 'branch1 commit')", 4267 "call dolt_checkout('main')", 4268 "call dolt_checkout('-b', 'branch2')", 4269 "insert into t1 (id, v1, v2) values (10, 11, 12)", 4270 "call dolt_commit('-Am', 'branch2 commit')", 4271 "call dolt_checkout('main')", 4272 }, 4273 Assertions: []queries.ScriptTestAssertion{ 4274 { 4275 Query: "call dolt_merge('branch1')", 4276 Expected: []sql.Row{{doltCommit, 1, 0, "merge successful"}}, 4277 }, 4278 { 4279 Query: "select * from t1 order by id", 4280 Expected: []sql.Row{ 4281 {1, 2, 3, 5}, 4282 {4, 5, 6, 11}, 4283 {7, 8, 9, 17}, 4284 }, 4285 }, 4286 { 4287 Query: "select id from t1 where v3 = 17", 4288 Expected: []sql.Row{{7}}, 4289 }, 4290 { 4291 Query: "call dolt_merge('branch2')", 4292 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 4293 }, 4294 { 4295 Query: "select * from t1 order by id", 4296 Expected: []sql.Row{ 4297 {1, 2, 3, 5}, 4298 {4, 5, 6, 11}, 4299 {7, 8, 9, 17}, 4300 {10, 11, 12, 23}, 4301 }, 4302 }, 4303 { 4304 Query: "select id from t1 where v3 = 23", 4305 Expected: []sql.Row{{10}}, 4306 }, 4307 }, 4308 }, 4309 { 4310 Name: "merge a virtual column created on another branch", 4311 SetUpScript: []string{ 4312 "create table t1 (id bigint primary key, v1 bigint, v2 bigint)", 4313 "insert into t1 (id, v1, v2) values (1, 2, 3), (4, 5, 6)", 4314 "call dolt_commit('-Am', 'first commit')", 4315 "call dolt_branch('branch1')", 4316 "insert into t1 (id, v1, v2) values (7, 8, 9)", 4317 "call dolt_commit('-Am', 'main commit')", 4318 "call dolt_checkout('branch1')", 4319 "alter table t1 add column v3 bigint as (v1 + v2)", 4320 "alter table t1 add key idx_v3 (v3)", 4321 "insert into t1 (id, v1, v2) values (10, 11, 12)", 4322 "call dolt_commit('-Am', 'branch1 commit')", 4323 "call dolt_checkout('main')", 4324 }, 4325 Assertions: []queries.ScriptTestAssertion{ 4326 { 4327 Query: "call dolt_merge('branch1')", 4328 Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}}, 4329 }, 4330 { 4331 Query: "select * from t1 order by id", 4332 Expected: []sql.Row{ 4333 {1, 2, 3, 5}, 4334 {4, 5, 6, 11}, 4335 {7, 8, 9, 17}, 4336 {10, 11, 12, 23}, 4337 }, 4338 }, 4339 { 4340 Query: "select id from t1 where v3 = 17", 4341 Expected: []sql.Row{{7}}, 4342 }, 4343 { 4344 Query: "select id from t1 where v3 = 23", 4345 Expected: []sql.Row{{10}}, 4346 }, 4347 }, 4348 }, 4349 } 4350 4351 // convertMergeScriptTest converts a MergeScriptTest into a standard ScriptTest. If flipSides is true, then the 4352 // left and right setup is swapped (i.e. left setup is done on right branch and right setup is done on main branch). 4353 // This enables us to test merges in both directions, since the merge code is asymmetric and some code paths currently 4354 // only run on the left side of the merge. 4355 func convertMergeScriptTest(mst MergeScriptTest, flipSides bool) queries.ScriptTest { 4356 setupScript := make([]string, 100) 4357 4358 // Ancestor setup 4359 setupScript = append(setupScript, mst.AncSetUpScript...) 4360 setupScript = append(setupScript, "CALL DOLT_COMMIT('-Am', 'ancestor commit');") 4361 setupScript = append(setupScript, "CALL DOLT_BRANCH('right');") 4362 4363 // Right-side setup 4364 if flipSides { 4365 setupScript = append(setupScript, "CALL DOLT_CHECKOUT('main');") 4366 } else { 4367 setupScript = append(setupScript, "CALL DOLT_CHECKOUT('right');") 4368 } 4369 setupScript = append(setupScript, mst.RightSetUpScript...) 4370 setupScript = append(setupScript, "CALL DOLT_COMMIT('-Am', 'right commit');") 4371 4372 // Left-side setup 4373 if flipSides { 4374 setupScript = append(setupScript, "CALL DOLT_CHECKOUT('right');") 4375 } else { 4376 setupScript = append(setupScript, "CALL DOLT_CHECKOUT('main');") 4377 } 4378 setupScript = append(setupScript, mst.LeftSetUpScript...) 4379 setupScript = append(setupScript, "CALL DOLT_COMMIT('-Am', 'left commit');") 4380 4381 // Always run the tests with the main branch checked out 4382 if flipSides { 4383 setupScript = append(setupScript, "CALL DOLT_CHECKOUT('main');") 4384 } 4385 4386 // Any assertions referencing our_ or their_ need to be flipped 4387 assertions := make([]queries.ScriptTestAssertion, len(mst.Assertions)) 4388 copy(assertions, mst.Assertions) 4389 if flipSides { 4390 for i, assertion := range assertions { 4391 assertions[i].Query = flipStatement(assertion.Query) 4392 } 4393 } 4394 4395 return queries.ScriptTest{ 4396 Name: mst.Name, 4397 SetUpScript: setupScript, 4398 Assertions: assertions, 4399 Query: mst.Query, 4400 Expected: mst.Expected, 4401 ExpectedErr: mst.ExpectedErr, 4402 SkipPrepared: mst.SkipPrepared, 4403 } 4404 } 4405 4406 // flipStatement replaces "our_" with "their_" and vice versa in the given query |s| so that the 4407 // query can be re-used to test a merge in the opposite direction. 4408 func flipStatement(s string) string { 4409 newS := strings.ReplaceAll(s, "our_", "temp_") 4410 newS = strings.ReplaceAll(newS, "their_", "our_") 4411 newS = strings.ReplaceAll(newS, "temp_", "their_") 4412 return newS 4413 }