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

schemadiff: consistent key ordering in table diff #17141

Merged
Show file tree
Hide file tree
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
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just typo fix

// 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)
}
Comment on lines +1714 to +1717
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent ordering iteration

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