Add LocalScale deploy request state machine#6
Merged
Conversation
a8f8d99 to
70755ac
Compare
There was a problem hiding this comment.
Pull request overview
Adds a full deploy-request lifecycle to LocalScale’s fake PlanetScale API so the engine can be tested end-to-end (branch → deploy → cutover → revert/skip) without a real PlanetScale account.
Changes:
- Introduces
localscale_deploy_requestsmetadata table and HTTP endpoints for deploy-request CRUD + actions (deploy, cancel, cutover, revert, skip-revert, throttle). - Adds a background processor that polls Vitess migration status and advances deploy-request states automatically.
- Extends LocalScale configuration/CLI config to support revert-window timing, default throttling, and optional artificial delays.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/localscale/server.go | Wires new deploy-request routes, starts/stops background processor, adds config fields and reset behavior. |
| pkg/localscale/schema/localscale_deploy_requests.sql | New metadata table backing the deploy-request state machine. |
| pkg/localscale/processor.go | Background state machine that derives deploy-request state from Vitess migration status. |
| pkg/localscale/helpers.go | Adds helpers for DDL strategy, schema snapshot/diff for revert, deploy request utilities, and branch DB cleanup. |
| pkg/localscale/handlers_deploy.go | Implements deploy-request create/get and deploy initiation flows. |
| pkg/localscale/handlers_actions.go | Implements deploy-request action endpoints (cancel/cutover/revert/skip/throttle) and Vitess migration helpers. |
| pkg/localscale/handlers_branches.go | Updates branch creation snapshot flow and adds optional artificial delay. |
| cmd/localscale/main.go | Adds CLI config parsing for new durations and throttle configuration. |
Comments suppressed due to low confidence (1)
pkg/localscale/handlers_branches.go:165
- Branch databases are now created on backend.mysqlDSNBase, but most branch operations (e.g., openBranchDB used by GET branch schema / apply branch schema / admin branch-db-query) still connect via s.branchDSNBase (derived from the first managed cluster). With multiple org/database backends this will create branch DBs on one mysqld and try to read/write them on another. Consider either keeping branch DBs on the shared metadata mysqld, or refactoring openBranchDB and all branch DB operations to use the per-backend mysqlDSNBase.
// Open a connection to the backend's mysqld for branch database creation.
// Each org/database has its own managed cluster with its own mysqld.
s.logger.Info("branch snapshot: opening backend mysqld", "dsn_prefix", backend.mysqlDSNBase[:min(len(backend.mysqlDSNBase), 40)])
backendDB, err := sql.Open("mysql", backend.mysqlDSNBase)
if err != nil {
s.logger.Error("open backend mysqld for branch creation", "error", err)
snapshotFailed = true
snapshotErrors = append(snapshotErrors, fmt.Sprintf("open backend mysqld: %v", err))
}
if backendDB != nil {
if err := backendDB.PingContext(bgCtx); err != nil {
s.logger.Error("ping backend mysqld for branch creation", "error", err)
utils.CloseAndLog(backendDB)
backendDB = nil
snapshotFailed = true
snapshotErrors = append(snapshotErrors, fmt.Sprintf("ping backend mysqld: %v", err))
} else {
defer utils.CloseAndLog(backendDB)
}
}
// Snapshot schema from vtgate into branch databases for each keyspace.
s.logger.Info("branch snapshot: iterating keyspaces", "count", len(backend.vtgateDBs), "branch", body.Name)
for keyspace := range backend.vtgateDBs {
s.logger.Info("branch snapshot: processing keyspace", "keyspace", keyspace, "branch", body.Name)
dbName := branchDBName(body.Name, keyspace)
if backendDB == nil {
snapshotFailed = true
continue
}
// Create branch database on the backend's mysqld
if err := validateIdentifier(dbName); err != nil {
s.logger.Error("invalid branch database name", "name", dbName, "error", err)
snapshotFailed = true
snapshotErrors = append(snapshotErrors, fmt.Sprintf("invalid branch database name %s: %v", dbName, err))
continue
}
if _, err := backendDB.ExecContext(bgCtx, "CREATE DATABASE IF NOT EXISTS "+quoteIdentifier(dbName)); err != nil {
s.logger.Error("create branch database", "branch", body.Name, "keyspace", keyspace, "error", err)
snapshotFailed = true
snapshotErrors = append(snapshotErrors, fmt.Sprintf("create branch database %s: %v", keyspace, err))
continue
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c993bd6 to
deafec5
Compare
a3d2906 to
31ad58f
Compare
Add a deploy request lifecycle to LocalScale's fake PlanetScale API, enabling end-to-end testing of the PlanetScale engine's branch→deploy→cutover→revert flow without a real PlanetScale account. The state machine processor runs as a background goroutine, polling Vitess migration statuses every 500ms and driving deploy requests through their lifecycle: pending → ready → submitting → queued → in_progress → pending_cutover → complete_pending_revert → complete. Supports cancel, revert (via reverse DDL computation), skip-revert, throttle control, and auto-cutover. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
31ad58f to
4944f91
Compare
morgo
approved these changes
Apr 10, 2026
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.
Summary
Adds a deploy request lifecycle to LocalScale's fake PlanetScale API, enabling end-to-end testing of the PlanetScale engine's branch→deploy→cutover→revert flow without a real PlanetScale account.
🤖 Generated with Claude Code