From cf99d542f08db4e89c11e371e056c014d1de7262 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Mon, 30 Sep 2024 14:47:22 -0400 Subject: [PATCH] Make auto generated sequence table name a const Signed-off-by: Matt Lord --- go/vt/vtctl/workflow/materializer.go | 3 ++- go/vt/vtctl/workflow/materializer_test.go | 4 ++-- go/vt/vtctl/workflow/traffic_switcher_test.go | 14 ++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/go/vt/vtctl/workflow/materializer.go b/go/vt/vtctl/workflow/materializer.go index 3d96d23da49..3789fc92e0a 100644 --- a/go/vt/vtctl/workflow/materializer.go +++ b/go/vt/vtctl/workflow/materializer.go @@ -51,6 +51,7 @@ const ( createDDLAsCopy = "copy" createDDLAsCopyDropConstraint = "copy:drop_constraint" createDDLAsCopyDropForeignKeys = "copy:drop_foreign_keys" + autoSequenceTableFormat = "%s_seq" ) type materializer struct { @@ -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{ diff --git a/go/vt/vtctl/workflow/materializer_test.go b/go/vt/vtctl/workflow/materializer_test.go index eea46e9a6aa..eb3fa39db16 100644 --- a/go/vt/vtctl/workflow/materializer_test.go +++ b/go/vt/vtctl/workflow/materializer_test.go @@ -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 @@ -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), }, }, }, diff --git a/go/vt/vtctl/workflow/traffic_switcher_test.go b/go/vt/vtctl/workflow/traffic_switcher_test.go index b0e8ca2037c..aca73476bdf 100644 --- a/go/vt/vtctl/workflow/traffic_switcher_test.go +++ b/go/vt/vtctl/workflow/traffic_switcher_test.go @@ -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 { @@ -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, @@ -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, @@ -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), }, }, },