Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schemadiff: adding a FK dependency unit test #16069

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, // [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 @@ -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
Loading