Skip to content

Add CLI parameters for move-tables feature#1702

Open
danieljoos wants to merge 3 commits into
move-tables-devfrom
move-tables/cli
Open

Add CLI parameters for move-tables feature#1702
danieljoos wants to merge 3 commits into
move-tables-devfrom
move-tables/cli

Conversation

@danieljoos

Copy link
Copy Markdown
Contributor

A Pull Request should be associated with an Issue.

We wish to have discussions in Issues. A single issue may be targeted by multiple PRs.
If you're offering a new feature or fixing anything, we'd like to know beforehand in Issues,
and potentially we'll be able to point development in a particular direction.

Related issue (public): #1681
Related issue (internal): https://github.com/github/database-infrastructure/issues/8167

Further notes in https://github.com/github/gh-ost/blob/master/.github/CONTRIBUTING.md
Thank you! We are open to PRs, but please understand if for technical reasons we are unable to accept each and any PR

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.

In case this PR introduced Go code changes:

  • contributed code is using same conventions as original code
  • script/cibuild returns with no formatting errors, build errors or unit test errors.

Copilot AI review requested due to automatic review settings June 9, 2026 18:02
@danieljoos danieljoos added the feature-move-tables PRs that are associated with the new move-tables feature label Jun 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-tables and target connection flags (--target-host, --target-port, --target-user, --target-password, --target-database) to the CLI.
  • Add MigrationContext.MoveTables plus IsMoveTablesMode() 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 thread go/cmd/gh-ost/main.go
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 thread go/cmd/gh-ost/main.go
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 thread go/cmd/gh-ost/main.go
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 thread go/cmd/gh-ost/main.go
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 thread go/logic/migrator.go
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 thread go/logic/migrator.go
Comment on lines +841 to +846
if err := mgtr.countTableRows(); err != nil {
return err
}
if err := mgtr.addDMLEventsListener(); err != nil {
return err
}
Comment thread go/logic/migrator.go
Comment on lines +831 to +834
// Validation complete! Run on-validated hook.
if err := mgtr.hooksExecutor.OnValidated(); err != nil {
return err
}
Comment thread go/logic/migrator.go
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-move-tables PRs that are associated with the new move-tables feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants