From 8e58aecf3dd8d94b9c85b8fa18c00d3542bb4d48 Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Sun, 20 Aug 2023 06:40:48 -0400 Subject: [PATCH] standard ghost/ptosc names Signed-off-by: Andrew Mason --- go/vt/vtctl/schematools/schematools.go | 5 ++ go/vt/vtctl/schematools/schematools_test.go | 69 +++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 go/vt/vtctl/schematools/schematools_test.go diff --git a/go/vt/vtctl/schematools/schematools.go b/go/vt/vtctl/schematools/schematools.go index 82151f9d545..059b7ca3db8 100644 --- a/go/vt/vtctl/schematools/schematools.go +++ b/go/vt/vtctl/schematools/schematools.go @@ -92,6 +92,11 @@ func SchemaMigrationStrategyName(strategy vtctldatapb.SchemaMigration_Strategy) return "unknown" } + switch strategy { + case vtctldatapb.SchemaMigration_GHOST, vtctldatapb.SchemaMigration_PTOSC: + name = strings.Join([]string{name[:2], name[2:]}, "-") + } + return strings.ToLower(name) } diff --git a/go/vt/vtctl/schematools/schematools_test.go b/go/vt/vtctl/schematools/schematools_test.go new file mode 100644 index 00000000000..94909ab52b1 --- /dev/null +++ b/go/vt/vtctl/schematools/schematools_test.go @@ -0,0 +1,69 @@ +/* +Copyright 2023 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package schematools + +import ( + "testing" + + vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" + + "github.com/stretchr/testify/assert" +) + +func TestSchemaMigrationStrategyName(t *testing.T) { + t.Parallel() + + tests := []struct { + in vtctldatapb.SchemaMigration_Strategy + out string + }{ + { + in: vtctldatapb.SchemaMigration_ONLINE, + out: "vitess", + }, + { + in: vtctldatapb.SchemaMigration_VITESS, + out: "vitess", + }, + { + in: vtctldatapb.SchemaMigration_GHOST, + out: "gh-ost", + }, + { + in: vtctldatapb.SchemaMigration_PTOSC, + out: "pt-osc", + }, + { + in: vtctldatapb.SchemaMigration_DIRECT, + out: "direct", + }, + { + in: vtctldatapb.SchemaMigration_Strategy(-1), + out: "unknown", + }, + } + + for _, test := range tests { + test := test + t.Run(test.out, func(t *testing.T) { + t.Parallel() + + out := SchemaMigrationStrategyName(test.in) + assert.Equal(t, test.out, out) + }) + } +}