Skip to content

Commit d75e591

Browse files
committed
More tests
1 parent 6e780ab commit d75e591

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

testing/go/foreign_keys_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,68 @@ func TestForeignKeys(t *testing.T) {
388388
},
389389
},
390390
},
391+
{
392+
Name: "drop foreign key in another schema, on search path",
393+
SetUpScript: []string{
394+
"create schema parent",
395+
"create schema child",
396+
"create schema fake",
397+
"call dolt_commit('-Am', 'create schemas')",
398+
"set search_path to 'child, parent'",
399+
`create table parent.parent (pk int, val int, primary key(pk));`,
400+
`create table fake.parent (pk int, val int, primary key(pk));`,
401+
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id))",
402+
"INSERT INTO parent.parent VALUES (0, 0), (1, 1), (2,2)",
403+
"SELECT DOLT_COMMIT('-Am', 'new tables')",
404+
"INSERT INTO child.child VALUES (2, 'two', 2)",
405+
"ALTER TABLE child.child ADD FOREIGN KEY (test_pk) REFERENCES parent(pk)",
406+
},
407+
Assertions: []ScriptTestAssertion{
408+
{
409+
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
410+
ExpectedErr: "Foreign key violation",
411+
},
412+
{
413+
Query: "alter table child DROP constraint child_ibfk_1",
414+
SkipResultsCheck: true,
415+
},
416+
{
417+
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
418+
Expected: []sql.Row{},
419+
},
420+
},
421+
},
422+
{
423+
Name: "drop foreign key in another schema, no search path",
424+
Skip: true, // not getting the explicit schema name passed to the node
425+
SetUpScript: []string{
426+
"create schema parent",
427+
"create schema child",
428+
"create schema fake",
429+
"call dolt_commit('-Am', 'create schemas')",
430+
`create table parent.parent (pk int, val int, primary key(pk));`,
431+
`create table fake.parent (pk int, val int, primary key(pk));`,
432+
"CREATE TABLE child.child (id int, info varchar(255), test_pk int, primary key(id))",
433+
"INSERT INTO parent.parent VALUES (0, 0), (1, 1), (2,2)",
434+
"SELECT DOLT_COMMIT('-Am', 'new tables')",
435+
"INSERT INTO child.child VALUES (2, 'two', 2)",
436+
"ALTER TABLE child.child ADD FOREIGN KEY (test_pk) REFERENCES parent.parent(pk)",
437+
},
438+
Assertions: []ScriptTestAssertion{
439+
{
440+
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
441+
ExpectedErr: "Foreign key violation",
442+
},
443+
{
444+
Query: "alter table child.child DROP constraint child_ibfk_1",
445+
SkipResultsCheck: true,
446+
},
447+
{
448+
Query: "INSERT INTO child.child VALUES (3, 'three', 3)",
449+
Expected: []sql.Row{},
450+
},
451+
},
452+
},
391453
},
392454
)
393455
}

0 commit comments

Comments
 (0)