From 5ec2dae8e12bde4c8525de550ebb541027e44001 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:54:09 +0200 Subject: [PATCH] Online DDL: fix endtoend test dropping foreign key Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- .../scheduler/onlineddl_scheduler_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go b/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go index 627567441b1..575ecb91091 100644 --- a/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go +++ b/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go @@ -2147,7 +2147,7 @@ func testForeignKeys(t *testing.T) { }, { name: "drop foreign key from a child", - sql: "alter table child_table DROP FOREIGN KEY child_parent_fk", + sql: "alter table child_table DROP FOREIGN KEY ", // See "getting child_table constraint name" test step below. allowForeignKeys: true, expectHint: "child_hint", onlyIfFKOnlineDDLPossible: true, @@ -2212,6 +2212,19 @@ func testForeignKeys(t *testing.T) { }) } }) + t.Run("getting child_table constraint name", func(t *testing.T) { + // Due to how OnlineDDL works, the name of the foreign key constraint will not be the one we used in the CREATE TABLE statement. + // There's a specific test where we drop said constraint. So speficially for that test (or any similar future tests), we need to dynamically + // evaluate the constraint name. + rs := onlineddl.VtgateExecQuery(t, &vtParams, "select CONSTRAINT_NAME from information_schema.REFERENTIAL_CONSTRAINTS where TABLE_NAME='child_table'", "") + assert.Equal(t, 1, len(rs.Rows)) + row := rs.Named().Row() + assert.NotNil(t, row) + childTableConstraintName := row.AsString("CONSTRAINT_NAME", "") + assert.NotEmpty(t, childTableConstraintName) + testcase.sql = strings.ReplaceAll(testcase.sql, "", childTableConstraintName) + }) + var uuid string t.Run("run migration", func(t *testing.T) { if testcase.allowForeignKeys {