Skip to content

Commit

Permalink
schemadiff: adding a FK dependency unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed Jun 5, 2024
1 parent 6def783 commit 1c46727
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion go/vt/schemadiff/schema_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,22 @@ func TestSchemaDiff(t *testing.T) {
conflictingDiffs: 2,
instantCapability: InstantDDLCapabilityImpossible,
},
{
name: "add and drop FK, add and drop respective tables",
fromQueries: []string{
"create table t1 (id int primary key, p int, key p_idx (p));",
"create table t2 (id int primary key, p int, key p_idx (p), foreign key (p) references t1 (p) on delete no action);",
},
toQueries: []string{
"create table t2 (id int primary key, p int, key p_idx (p), foreign key (p) references t3 (p) on delete no action);",
"create table t3 (id int primary key, p int, key p_idx (p));",
},
expectDiffs: 3,
expectDeps: 2,
sequential: true,
entityOrder: []string{"t3", "t2", "t1"},
instantCapability: InstantDDLCapabilityImpossible,
},
{
name: "two identical foreign keys in table, drop one",
fromQueries: []string{
Expand Down Expand Up @@ -1051,7 +1067,7 @@ func TestSchemaDiff(t *testing.T) {
for _, dep := range deps {
depsKeys = append(depsKeys, dep.hashKey())
}
assert.Equalf(t, tc.expectDeps, len(deps), "found deps: %v", depsKeys)
assert.Equalf(t, tc.expectDeps, len(deps), "found %v deps: %v", len(depsKeys), depsKeys)
assert.Equal(t, tc.sequential, schemaDiff.HasSequentialExecutionDependencies())

orderedDiffs, err := schemaDiff.OrderedDiffs(ctx)
Expand Down

0 comments on commit 1c46727

Please sign in to comment.