Skip to content

Add --branch flag for reusing existing PlanetScale branches#35

Draft
aparajon wants to merge 7 commits intoarmand/progress-template-keyspacefrom
armand/branch-reuse
Draft

Add --branch flag for reusing existing PlanetScale branches#35
aparajon wants to merge 7 commits intoarmand/progress-template-keyspacefrom
armand/branch-reuse

Conversation

@aparajon
Copy link
Copy Markdown
Collaborator

@aparajon aparajon commented Apr 24, 2026

Adds --branch flag to schemabot apply for reusing an existing PlanetScale branch instead of creating a new one. This skips the 60s+ branch creation wait by syncing an existing branch with main.

  • --branch <name> verifies the branch exists and is ready, syncs it with main via the PlanetScale API, waits for sync to complete, then continues with the normal DDL apply flow
  • Adds SyncBranch to the PS client (raw HTTP — not in the Go SDK)
  • Adds DeleteBranch to the PS client interface

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 24, 2026 13:25
@aparajon aparajon force-pushed the armand/branch-reuse branch from e720542 to 856ac5f Compare April 24, 2026 13:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for reusing an existing PlanetScale branch during schemabot apply by introducing a --branch <name> option that attempts to sync that branch with main before continuing the normal apply flow (to avoid the branch-creation wait).

Changes:

  • Add --branch flag to the CLI apply command and plumb it through the apply API options.
  • Extend the PlanetScale engine apply flow to reuse/sync an existing branch when requested.
  • Extend the PlanetScale client interface with SyncBranch (raw HTTP) and DeleteBranch.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkg/psclient/client.go Adds DeleteBranch and raw-HTTP SyncBranch to the PS client wrapper/interface.
pkg/engine/planetscale/planetscale.go Updates Apply() to reuse/sync an existing branch when options["branch"] is set.
pkg/cmd/commands/rollback.go Updates call site for applyAndWatch signature change.
pkg/cmd/commands/common.go Adds branch parameter and forwards it as options["branch"] to the apply API.
pkg/cmd/commands/apply.go Adds --branch flag and validates it’s only used with Vitess/PlanetScale engines.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/psclient/client.go Outdated
Comment thread pkg/psclient/client.go Outdated
Comment thread pkg/engine/planetscale/planetscale.go
Comment thread pkg/engine/planetscale/planetscale.go Outdated
Comment thread pkg/engine/planetscale/planetscale.go Outdated
@aparajon aparajon force-pushed the armand/branch-reuse branch from 856ac5f to 9ea3eb0 Compare April 24, 2026 13:45
@aparajon aparajon changed the base branch from main to armand/progress-fixes April 24, 2026 13:46
Base automatically changed from armand/progress-fixes to main April 24, 2026 15:20
@aparajon aparajon force-pushed the armand/branch-reuse branch 4 times, most recently from b2daa02 to f72710d Compare April 24, 2026 20:03
aparajon and others added 6 commits April 24, 2026 17:13
Adds branch reuse support to skip the ~60s (or ~10min for 30+ keyspaces)
branch creation phase. When --branch is specified, the engine syncs the
existing branch with main instead of creating a new one.

CLI: --branch flag on apply command, validated as Vitess-only.
Engine: checks for options["branch"], calls SyncBranch API instead of
CreateBranch, waits for sync to complete, then proceeds with DDL.
PSClient: added SyncBranch (raw HTTP, not in Go SDK) and DeleteBranch.

Also fixes skip_revert not being passed through the apply options map.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implements branch sync for LocalScale: drops existing branch databases,
re-snapshots schema from main via vtgate, and marks the branch ready.
This is the LocalScale equivalent of PlanetScale's branch sync API.

Integration tests verify:
- TestSyncBranch: sync removes branch-only schema changes
- TestSyncBranchAndApply: full branch reuse workflow with two
  consecutive deploys on the same branch

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Default baseURL for SyncBranch so it works with NewPSClient
- Include response body in SyncBranch HTTP errors
- Reject --branch main to prevent applying DDL to the main branch
- Disable auto-delete when reusing a branch so it survives for reuse

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reject --branch main early in the CLI before sending to the server.
The engine already rejects it server-side, but client-side gives
faster feedback. Both checks protect against applying DDL directly
to the main branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ShardProgress adds an INDEX to a 2-shard table. In -o log mode, the
CLI blocks for the full lifecycle which exceeds the 30s CLI timeout on
slow CI runners. Use --no-watch so the CLI exits immediately, then
poll for shard progress during the running state when the engine is
live and SHOW VITESS_MIGRATIONS has shard data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TestVitess_Apply_BranchReuse creates a branch via LocalScale API, then
runs two consecutive applies using --branch flag through the full
CLI → server → engine path. Verifies branch sync, apply completion,
and branch survival for reuse.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aparajon aparajon force-pushed the armand/branch-reuse branch from 53a35df to cc88a68 Compare April 24, 2026 21:13
@aparajon aparajon changed the base branch from main to armand/progress-template-keyspace April 24, 2026 21:13
@aparajon aparajon force-pushed the armand/branch-reuse branch 3 times, most recently from 2f2150f to 9dd258f Compare April 24, 2026 22:59
The PlanetScale API uses /refresh-schema (not /sync) to update a
branch's schema from main. Use the SDK's RefreshSchema method instead
of raw HTTP. Rename throughout: SyncBranch → RefreshSchema, event
messages show "Refreshing branch schema" instead of "Syncing branch".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aparajon aparajon force-pushed the armand/branch-reuse branch from 9dd258f to 3fc419b Compare April 24, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants