Skip to content

Commit 1ca8ffc

Browse files
committed
Support altering index names with PanicOnWarnings
1 parent 1487b5c commit 1ca8ffc

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

go/logic/applier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
777777
this.migrationContext.Log.Warningf("Failed to read SHOW WARNINGS row")
778778
continue
779779
}
780-
migrationUniqueKeySuffix := fmt.Sprintf("for key '%s.%s'", this.migrationContext.GetGhostTableName(), this.migrationContext.UniqueKey.Name)
780+
migrationUniqueKeySuffix := fmt.Sprintf("for key '%s.%s'", this.migrationContext.GetGhostTableName(), this.migrationContext.UniqueKey.NameInGhostTable)
781781
if strings.HasPrefix(message, "Duplicate entry") && strings.HasSuffix(message, migrationUniqueKeySuffix) {
782782
continue
783783
}

go/logic/applier_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,9 @@ func (suite *ApplierTestSuite) TestPanicOnWarningsInApplyIterationInsertQuerySuc
531531
migrationContext.SharedColumns = sql.NewColumnList([]string{"id", "item_id"})
532532
migrationContext.MappedSharedColumns = sql.NewColumnList([]string{"id", "item_id"})
533533
migrationContext.UniqueKey = &sql.UniqueKey{
534-
Name: "item_id",
535-
Columns: *sql.NewColumnList([]string{"item_id"}),
534+
Name: "item_id",
535+
NameInGhostTable: "item_id",
536+
Columns: *sql.NewColumnList([]string{"item_id"}),
536537
}
537538

538539
applier := NewApplier(migrationContext)

go/logic/inspect.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,9 @@ func (this *Inspector) getSharedUniqueKeys(originalUniqueKeys, ghostUniqueKeys [
846846
for _, originalUniqueKey := range originalUniqueKeys {
847847
for _, ghostUniqueKey := range ghostUniqueKeys {
848848
if originalUniqueKey.Columns.IsSubsetOf(&ghostUniqueKey.Columns) {
849+
// In case the unique key gets renamed in -alter, PanicOnWarnings needs to rely on the new name
850+
// to check SQL warnings on the ghost table, so return new name here.
851+
originalUniqueKey.NameInGhostTable = ghostUniqueKey.Name
849852
uniqueKeys = append(uniqueKeys, originalUniqueKey)
850853
break
851854
}

go/sql/types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,11 @@ func (this *ColumnList) SetCharsetConversion(columnName string, fromCharset stri
265265

266266
// UniqueKey is the combination of a key's name and columns
267267
type UniqueKey struct {
268-
Name string
269-
Columns ColumnList
270-
HasNullable bool
271-
IsAutoIncrement bool
268+
Name string
269+
NameInGhostTable string // Name of the corresponding key in the Ghost table in case it is being renamed
270+
Columns ColumnList
271+
HasNullable bool
272+
IsAutoIncrement bool
272273
}
273274

274275
// IsPrimary checks if this unique key is primary

localtests/swap-uk-uk/extra_args

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--alter="drop key id_uidx, drop key its_uidx, add unique key its2_uidx(i, ts), add unique key id2_uidx(id)"
1+
--panic-on-warnings --alter="drop key id_uidx, drop key its_uidx, add unique key its2_uidx(i, ts), add unique key id2_uidx(id)"

0 commit comments

Comments
 (0)