diff --git a/go/vt/vtctl/workflow/traffic_switcher.go b/go/vt/vtctl/workflow/traffic_switcher.go index b762ad42f5f..65dcecb9623 100644 --- a/go/vt/vtctl/workflow/traffic_switcher.go +++ b/go/vt/vtctl/workflow/traffic_switcher.go @@ -1570,8 +1570,10 @@ func (ts *trafficSwitcher) findSequenceUsageInKeyspace(vschema *vschemapb.Keyspa err error ) if len(seqTable.ColumnVindexes[i].Columns) > 0 { - unescapedColumn, err = sqlescape.UnescapeID(seqTable.ColumnVindexes[i].Columns[0]) // AutoIncrement definitions can only be on a single column - seqTable.ColumnVindexes[i].Columns[0] = unescapedColumn + for n := range seqTable.ColumnVindexes[i].Columns { + unescapedColumn, err = sqlescape.UnescapeID(seqTable.ColumnVindexes[i].Columns[n]) + seqTable.ColumnVindexes[i].Columns[n] = unescapedColumn + } } else { // This is the legacy vschema definition. unescapedColumn, err = sqlescape.UnescapeID(seqTable.ColumnVindexes[i].Column) diff --git a/go/vt/vtctl/workflow/traffic_switcher_test.go b/go/vt/vtctl/workflow/traffic_switcher_test.go index 495b00d7144..4b3d17036c1 100644 --- a/go/vt/vtctl/workflow/traffic_switcher_test.go +++ b/go/vt/vtctl/workflow/traffic_switcher_test.go @@ -284,6 +284,55 @@ func TestGetTargetSequenceMetadata(t *testing.T) { }, }, }, + { + name: "sequence with table having mult-col vindex", + sourceVSchema: &vschema.Keyspace{ + Vindexes: vindexes, + Tables: map[string]*vschema.Table{ + "seq1": { + Type: "sequence", + }, + }, + }, + targetVSchema: &vschema.Keyspace{ + Vindexes: vindexes, + Tables: map[string]*vschema.Table{ + table: { + ColumnVindexes: []*vschema.ColumnVindex{ + { + Name: "xxhash", + Columns: []string{"col3", "col4"}, + }, + }, + AutoIncrement: &vschema.AutoIncrement{ + Column: "col1", + Sequence: fmt.Sprintf("%s.seq1", sourceKeyspace.KeyspaceName), + }, + }, + }, + }, + want: map[string]*sequenceMetadata{ + "seq1": { + backingTableName: "seq1", + backingTableKeyspace: "source-ks", + backingTableDBName: "vt_source-ks", + usingTableName: unescapedTable, + usingTableDBName: "vt_targetks", + usingTableDefinition: &vschema.Table{ + ColumnVindexes: []*vschema.ColumnVindex{ + { + Columns: []string{"col3", "col4"}, + Name: "xxhash", + }, + }, + AutoIncrement: &vschema.AutoIncrement{ + Column: "col1", + Sequence: fmt.Sprintf("%s.seq1", sourceKeyspace.KeyspaceName), + }, + }, + }, + }, + }, { name: "invalid table name", sourceVSchema: &vschema.Keyspace{