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

Online DDL: fix endtoend test dropping foreign key #14522

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
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
Loading