Skip to content

Commit

Permalink
schemadiff: consistent key ordering in table diff (#17141)
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 5, 2024
1 parent 012e601 commit f907205
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions go/vt/schemadiff/schema_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ func (d *SchemaDiff) UnorderedDiffs() []EntityDiff {
return d.diffs
}

// AllDependenciess returns all known dependencies
func (d *SchemaDiff) AllDependenciess() (deps []*DiffDependency) {
// AllDependencies returns all known dependencies
func (d *SchemaDiff) AllDependencies() (deps []*DiffDependency) {
for _, dep := range d.dependencies {
deps = append(deps, dep)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/schemadiff/schema_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ func TestSchemaDiff(t *testing.T) {
}
assert.Equalf(t, tc.expectDiffs, len(allDiffs), "found diffs: %v", allDiffsStatements)

deps := schemaDiff.AllDependenciess()
deps := schemaDiff.AllDependencies()
depsKeys := []string{}
for _, dep := range deps {
depsKeys = append(depsKeys, dep.hashKey())
Expand Down
6 changes: 4 additions & 2 deletions go/vt/schemadiff/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1711,8 +1711,10 @@ func (c *CreateTableEntity) diffKeys(alterTable *sqlparser.AlterTable,
}
}
}
for _, stmt := range dropKeyStatements {
alterTable.AlterOptions = append(alterTable.AlterOptions, stmt)
for _, t1Key := range t1Keys {
if stmt, ok := dropKeyStatements[t1Key.Info.Name.String()]; ok {
alterTable.AlterOptions = append(alterTable.AlterOptions, stmt)
}
}
return superfluousFulltextKeys
}
Expand Down
18 changes: 18 additions & 0 deletions go/vt/schemadiff/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,24 @@ func TestCreateTableDiff(t *testing.T) {
"- KEY `i_idx` (`i`)",
},
},
{
name: "multiple dropped keys and columns",
from: "create table t1 (`id` int, i1 int, i2 int, i3 int, primary key (id), key k1(i1), key k2(i2), key k3(i1), key k4(i2), key k5(i1), key k6(i2))",
to: "create table t1 (`id` int, primary key (id))",
diff: "alter table t1 drop key k1, drop key k2, drop key k3, drop key k4, drop key k5, drop key k6, drop column i1, drop column i2, drop column i3",
cdiff: "ALTER TABLE `t1` DROP KEY `k1`, DROP KEY `k2`, DROP KEY `k3`, DROP KEY `k4`, DROP KEY `k5`, DROP KEY `k6`, DROP COLUMN `i1`, DROP COLUMN `i2`, DROP COLUMN `i3`",
textdiffs: []string{
"- KEY `k1` (`i1`)",
"- KEY `k2` (`i2`)",
"- KEY `k3` (`i1`)",
"- KEY `k4` (`i2`)",
"- KEY `k5` (`i1`)",
"- KEY `k6` (`i2`)",
"- `i1` int,",
"- `i2` int,",
"- `i3` int,",
},
},
{
name: "modified key",
from: "create table t1 (`id` int primary key, i int, key i_idx(i))",
Expand Down

0 comments on commit f907205

Please sign in to comment.