Skip to content

Commit

Permalink
schemadiff: adding a FK dependency unit test (#16069)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach authored Jun 6, 2024
1 parent 307b290 commit 87ecae7
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 @@ -979,6 +979,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, // [alter t2]/[drop t1], [alter t2]/[create t3]
sequential: true,
entityOrder: []string{"t3", "t2", "t1"},
instantCapability: InstantDDLCapabilityImpossible,
},
{
name: "two identical foreign keys in table, drop one",
fromQueries: []string{
Expand Down Expand Up @@ -1053,7 +1069,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 87ecae7

Please sign in to comment.