Skip to content

Commit

Permalink
Make auto generated sequence table name a const
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Sep 30, 2024
1 parent 659929e commit cf99d54
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion go/vt/vtctl/workflow/materializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
createDDLAsCopy = "copy"
createDDLAsCopyDropConstraint = "copy:drop_constraint"
createDDLAsCopyDropForeignKeys = "copy:drop_foreign_keys"
autoSequenceTableFormat = "%s_seq"
)

type materializer struct {
Expand Down Expand Up @@ -379,7 +380,7 @@ func (mz *materializer) deploySchema() error {
table := targetVSchema.Tables[ts.TargetTable]
// Don't override or redo anything that already exists.
if table != nil && table.AutoIncrement == nil {
seqTableName := fmt.Sprintf("%s_seq", ts.TargetTable)
seqTableName := fmt.Sprintf(autoSequenceTableFormat, ts.TargetTable)
// Create a Vitess AutoIncrement definition -- which uses a sequence -- to
// replace the MySQL auto_increment definition that we removed.
table.AutoIncrement = &vschemapb.AutoIncrement{
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtctl/workflow/materializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func TestMoveTablesDDLFlag(t *testing.T) {
}
}

// TestShardedAutoIncHandlings tests the optional behaviors available when moving
// TestShardedAutoIncHandling tests the optional behaviors available when moving
// tables to a sharded keyspace and the tables being copied contain MySQL
// auto_increment clauses. The optional behaviors are:
// 1. LEAVE the tables' MySQL auto_increment clauses alone
Expand Down Expand Up @@ -847,7 +847,7 @@ func TestShardedAutoIncHandling(t *testing.T) {
},
AutoIncrement: &vschemapb.AutoIncrement{ // AutoIncrement definition added
Column: "id",
Sequence: fmt.Sprintf("%s_seq", tableName),
Sequence: fmt.Sprintf(autoSequenceTableFormat, tableName),
},
},
},
Expand Down
14 changes: 8 additions & 6 deletions go/vt/vtctl/workflow/traffic_switcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/sqlescape"
"vitess.io/vitess/go/vt/mysqlctl/tmutils"
"vitess.io/vitess/go/vt/proto/vschema"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/vtgate/vindexes"
"vitess.io/vitess/go/vt/vttablet/tabletmanager/vreplication"

tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

type testTrafficSwitcher struct {
Expand Down Expand Up @@ -182,7 +183,8 @@ func TestGetTargetSequenceMetadata(t *testing.T) {
},
expectSourceApplySchemaRequest: &applySchemaRequestResponse{
change: &tmutils.SchemaChange{
SQL: sqlparser.BuildParsedQuery(sqlCreateSequenceTable, fmt.Sprintf("`%s_seq`", unescapedTable)).Query,
SQL: sqlparser.BuildParsedQuery(sqlCreateSequenceTable,
sqlescape.EscapeID(fmt.Sprintf(autoSequenceTableFormat, unescapedTable))).Query,
Force: false,
AllowReplication: true,
SQLMode: vreplication.SQLMode,
Expand All @@ -202,14 +204,14 @@ func TestGetTargetSequenceMetadata(t *testing.T) {
},
AutoIncrement: &vschema.AutoIncrement{
Column: "my-col",
Sequence: fmt.Sprintf("%s_seq", unescapedTable),
Sequence: fmt.Sprintf(autoSequenceTableFormat, unescapedTable),
},
},
},
},
want: map[string]*sequenceMetadata{
fmt.Sprintf("%s_seq", unescapedTable): {
backingTableName: fmt.Sprintf("%s_seq", unescapedTable),
fmt.Sprintf(autoSequenceTableFormat, unescapedTable): {
backingTableName: fmt.Sprintf(autoSequenceTableFormat, unescapedTable),
backingTableKeyspace: "source-ks",
backingTableDBName: "vt_source-ks",
usingTableName: unescapedTable,
Expand All @@ -223,7 +225,7 @@ func TestGetTargetSequenceMetadata(t *testing.T) {
},
AutoIncrement: &vschema.AutoIncrement{
Column: "my-col",
Sequence: fmt.Sprintf("%s_seq", unescapedTable),
Sequence: fmt.Sprintf(autoSequenceTableFormat, unescapedTable),
},
},
},
Expand Down

0 comments on commit cf99d54

Please sign in to comment.