Skip to content

Commit 2b84cc4

Browse files
Merge branch 'feature-move-tables' into move-tables/applier-dml-events
2 parents 7e876a0 + 84f1c61 commit 2b84cc4

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

go/cmd/gh-ost/main.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"os/signal"
1414
"regexp"
15+
"slices"
1516
"strings"
1617
"syscall"
1718
"time"
@@ -187,7 +188,7 @@ func main() {
187188
flag.StringVar(&migrationContext.ForceTmpTableName, "force-table-names", "", "table name prefix to be used on the temporary tables")
188189

189190
// move tables flags
190-
moveTables := flag.String("move-tables", "", "Comma delimited list of tables to move. e.g. 'table1,table2,table3'. This is a special mode that allows you to move tables between database clusters. This mode is mutually exclusive with --alter, --table, --test-on-replica, --migrate-on-replica, --execute-on-replica, and --revert.")
191+
moveTables := flag.String("move-tables", "", "Comma delimited list of tables to move. e.g. 'table1,table2,table3'. This is a special mode that allows you to move tables between database clusters. This mode is mutually exclusive with --alter, --table, --test-on-replica, --migrate-on-replica and --revert.")
191192
flag.StringVar(&migrationContext.MoveTables.TargetHost, "target-host", "", "Target MySQL hostname for --move-tables mode. Must be specified if --move-tables is specified.")
192193
flag.IntVar(&migrationContext.MoveTables.TargetPort, "target-port", 3306, "Target MySQL port for --move-tables mode. Defaults to 3306.")
193194
flag.StringVar(&migrationContext.MoveTables.TargetUser, "target-user", "", "Target MySQL username for --move-tables mode. If not provided, uses the same user as the source connection")
@@ -238,8 +239,8 @@ func main() {
238239

239240
migrationContext.SetConnectionCharset(*charset)
240241

241-
if migrationContext.AlterStatement == "" && !migrationContext.Revert {
242-
log.Fatal("--alter must be provided and statement must not be empty")
242+
if migrationContext.AlterStatement == "" && !migrationContext.Revert && *moveTables == "" {
243+
log.Fatal("--alter must be provided and statement must not be empty, or --revert must be used, or --move-tables must be used")
243244
}
244245
parser := sql.NewParserFromAlterStatement(migrationContext.AlterStatement)
245246
migrationContext.AlterStatementOptions = parser.GetAlterStatementOptions()
@@ -279,7 +280,7 @@ func main() {
279280
migrationContext.Log.Fatale(err)
280281
}
281282

282-
if migrationContext.OriginalTableName == "" {
283+
if migrationContext.OriginalTableName == "" && *moveTables == "" {
283284
if parser.HasExplicitTable() {
284285
migrationContext.OriginalTableName = parser.GetExplicitTable()
285286
} else {
@@ -369,11 +370,24 @@ func main() {
369370
log.Fatal("--target-host must be specified when using --move-tables")
370371
}
371372
migrationContext.MoveTables.TableNames = strings.Split(*moveTables, ",")
373+
for i := range migrationContext.MoveTables.TableNames {
374+
migrationContext.MoveTables.TableNames[i] = strings.TrimSpace(migrationContext.MoveTables.TableNames[i])
375+
}
376+
migrationContext.MoveTables.TableNames = slices.DeleteFunc(migrationContext.MoveTables.TableNames, func(s string) bool { return s == "" })
372377
if len(migrationContext.MoveTables.TableNames) > 1 {
373378
// Future version will support moving multiple tables at the same time.
374379
// For now, we only support moving a single table at a time.
375380
log.Fatal("--move-tables currently supports only a single table")
376381
}
382+
if migrationContext.MoveTables.TargetUser == "" {
383+
migrationContext.MoveTables.TargetUser = migrationContext.CliUser
384+
}
385+
if migrationContext.MoveTables.TargetPass == "" {
386+
migrationContext.MoveTables.TargetPass = migrationContext.CliPassword
387+
}
388+
if migrationContext.MoveTables.TargetDatabase == "" {
389+
migrationContext.MoveTables.TargetDatabase = migrationContext.DatabaseName
390+
}
377391
}
378392

379393
switch *cutOver {

0 commit comments

Comments
 (0)