From 1c467275d07167c13cb69782ce64c6d116a44d9d Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:47:02 +0300 Subject: [PATCH 1/2] schemadiff: adding a FK dependency unit test Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/schemadiff/schema_diff_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/go/vt/schemadiff/schema_diff_test.go b/go/vt/schemadiff/schema_diff_test.go index 3dc1ab291fd..75b5599f39c 100644 --- a/go/vt/schemadiff/schema_diff_test.go +++ b/go/vt/schemadiff/schema_diff_test.go @@ -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{ @@ -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) From b2d882a9b576a5fa49aaeffa64af5ecc5a2c6474 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:59:11 +0300 Subject: [PATCH 2/2] code comment Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/schemadiff/schema_diff_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/schemadiff/schema_diff_test.go b/go/vt/schemadiff/schema_diff_test.go index 75b5599f39c..cf8a85fcff2 100644 --- a/go/vt/schemadiff/schema_diff_test.go +++ b/go/vt/schemadiff/schema_diff_test.go @@ -988,7 +988,7 @@ func TestSchemaDiff(t *testing.T) { "create table t3 (id int primary key, p int, key p_idx (p));", }, expectDiffs: 3, - expectDeps: 2, + expectDeps: 2, // [alter t2]/[drop t1], [alter t2]/[create t3] sequential: true, entityOrder: []string{"t3", "t2", "t1"}, instantCapability: InstantDDLCapabilityImpossible,