Add CLI parameters for move-tables feature#1702
Open
danieljoos wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces initial scaffolding for the “move-tables” feature by adding new CLI flags and a new migrator entrypoint intended to run a move-tables workflow.
Changes:
- Add
--move-tablesand target connection flags (--target-host,--target-port,--target-user,--target-password,--target-database) to the CLI. - Add
MigrationContext.MoveTablesplusIsMoveTablesMode()to switch execution into the move-tables path. - Add a new
Migrator.MoveTables()method and route execution to it when move-tables mode is enabled.
Show a summary per file
| File | Description |
|---|---|
| go/logic/migrator.go | Adds a new MoveTables() workflow entrypoint (currently incomplete and missing required initialization/cutover). |
| go/cmd/gh-ost/main.go | Adds CLI flags + validation and routes execution to MoveTables() when enabled. |
| go/base/context.go | Adds move-tables configuration fields to MigrationContext and a helper to detect the mode. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 8
Comment on lines
+189
to
+191
| // move tables flags | ||
| 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.") | ||
| flag.StringVar(&migrationContext.MoveTables.TargetHost, "target-host", "", "Target MySQL hostname for --move-tables mode. Must be specified if --move-tables is specified.") |
Comment on lines
+352
to
+357
| if *moveTables != "" { | ||
| if migrationContext.AlterStatement != "" { | ||
| log.Fatal("--move-tables is mutually exclusive with --alter") | ||
| } | ||
| if migrationContext.OriginalTableName != "" { | ||
| log.Fatal("--move-tables is mutually exclusive with --table") |
Comment on lines
+371
to
+376
| migrationContext.MoveTables.TableNames = strings.Split(*moveTables, ",") | ||
| if len(migrationContext.MoveTables.TableNames) > 1 { | ||
| // Future version will support moving multiple tables at the same time. | ||
| // For now, we only support moving a single table at a time. | ||
| log.Fatal("--move-tables currently supports only a single table") | ||
| } |
Comment on lines
+193
to
+195
| 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") | ||
| flag.StringVar(&migrationContext.MoveTables.TargetPass, "target-password", "", "Target MySQL password for --move-tables mode. If not provided, uses the same password as the source connection") | ||
| flag.StringVar(&migrationContext.MoveTables.TargetDatabase, "target-database", "", "Target MySQL database name for --move-tables mode. If not provided, uses the same database name as the source connection") |
Comment on lines
+794
to
+798
| mgtr.migrationContext.Log.Infof("Moving tables %v from %s to %s (%s)", | ||
| mgtr.migrationContext.MoveTables.TableNames, | ||
| sql.EscapeName(mgtr.migrationContext.DatabaseName), | ||
| sql.EscapeName(mgtr.migrationContext.MoveTables.TargetDatabase), mgtr.migrationContext.MoveTables.TargetHost) | ||
| mgtr.migrationContext.StartTime = time.Now() |
Comment on lines
+841
to
+846
| if err := mgtr.countTableRows(); err != nil { | ||
| return err | ||
| } | ||
| if err := mgtr.addDMLEventsListener(); err != nil { | ||
| return err | ||
| } |
Comment on lines
+831
to
+834
| // Validation complete! Run on-validated hook. | ||
| if err := mgtr.hooksExecutor.OnValidated(); err != nil { | ||
| return err | ||
| } |
Comment on lines
+878
to
+894
| //TODO: cutover here | ||
|
|
||
| if err := mgtr.finalCleanup(); err != nil { | ||
| return nil | ||
| } | ||
| if err := mgtr.hooksExecutor.OnSuccess(false); err != nil { | ||
| return err | ||
| } | ||
| mgtr.migrationContext.Log.Infof("Done moving tables %v from %s to %s (%s)", | ||
| mgtr.migrationContext.MoveTables.TableNames, sql.EscapeName(mgtr.migrationContext.DatabaseName), | ||
| sql.EscapeName(mgtr.migrationContext.MoveTables.TargetDatabase), mgtr.migrationContext.MoveTables.TargetHost) | ||
| // Final check for abort before declaring success | ||
| if err := mgtr.checkAbort(); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Pull Request should be associated with an Issue.
Related issue (public): #1681
Related issue (internal): https://github.com/github/database-infrastructure/issues/8167
Description
This PR is part of the move-tables feature.
It introduces CLI flags for enabling the move-tables mode and to specify the destination database.
script/cibuildreturns with no formatting errors, build errors or unit test errors.