Skip to content

Commit

Permalink
Online DDL: fix endtoend test dropping foreign key (#14522)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach authored Nov 15, 2023
1 parent 024af93 commit c823b86
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <childTableConstraintName>", // See "getting child_table constraint name" test step below.
allowForeignKeys: true,
expectHint: "child_hint",
onlyIfFKOnlineDDLPossible: true,
Expand Down Expand Up @@ -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>", childTableConstraintName)
})

var uuid string
t.Run("run migration", func(t *testing.T) {
if testcase.allowForeignKeys {
Expand Down

0 comments on commit c823b86

Please sign in to comment.