Skip to content

fix(planetscale): turn off auto-apply on every deploy request SchemaBot creates - #965

Draft
aparajon wants to merge 1 commit into
mainfrom
armand/ps-disable-auto-apply
Draft

fix(planetscale): turn off auto-apply on every deploy request SchemaBot creates#965
aparajon wants to merge 1 commit into
mainfrom
armand/ps-disable-auto-apply

Conversation

@aparajon

@aparajon aparajon commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Why this matters

SchemaBot is the sole cutover actor on PlanetScale: a deploy request must park at pending_cutover so the driver — or the operator holding a deferred cutover — decides when the schema swaps. Today --defer-cutover is a no-op there.

The create request cannot express the intent. The SDK tags CreateDeployRequestRequest.AutoCutover omitempty, so false is the zero value and "auto-cutover off" serializes identically to "unspecified". The deploy request then inherits the database's own remembered auto-apply default, which may be on, and cuts over unattended.

What it does

  • Turns auto-apply off on every deploy request immediately after creation, through the auto-apply endpoint, whose flag is sent unconditionally. A deploy request whose auto-apply could not be turned off is refused rather than driven — SchemaBot cannot guarantee it owns the swap.
  • Grows the same endpoint in the local emulator, and makes an absent auto_cutover on create default to on, the way the remembered default can. Defaulting it off made a caller that never stated its intent look correct.

🤖 Generated with Claude Code

…ot creates

SchemaBot is the sole cutover actor on PlanetScale: a deploy request must
park at pending_cutover so the driver — or the operator holding a deferred
cutover — decides when the schema swaps.

The create request cannot express that. The SDK tags
CreateDeployRequestRequest.AutoCutover `omitempty`, so false is the zero
value and "auto-cutover off" serializes identically to "unspecified". The
deploy request then inherits the database's own remembered auto-apply
default, which may be on, and cuts over unattended. Stating the intent
requires the auto-apply endpoint, whose flag is sent unconditionally.

Every deploy request now has auto-apply turned off immediately after
creation, and a deploy request whose auto-apply could not be turned off is
refused rather than driven — SchemaBot cannot guarantee it owns the swap.

LocalScale grows the same endpoint, and an absent auto_cutover on create
now defaults to on the way PlanetScale's remembered default can. Defaulting
it off made a caller that never stated its intent look correct.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 7, 2026 19:12

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

Ensures SchemaBot remains the sole cutover actor for PlanetScale deploy requests by explicitly disabling auto-apply immediately after deploy request creation (working around the Go SDK’s omitempty behavior), and extends LocalScale to emulate the same semantics.

Changes:

  • Add PSClient.DisableAutoApply and implement it via the PlanetScale auto-apply endpoint.
  • Update the PlanetScale engine to disable auto-apply right after creating a deploy request and refuse to proceed if it can’t be disabled.
  • Extend LocalScale with the auto-apply endpoint and make create-deploy default auto_cutover to “on” when the field is absent; update integration/unit tests accordingly.

Reviewed changes

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

Show a summary per file
File Description
pkg/psclient/client.go Adds a DisableAutoApply API to reliably force auto-apply off on deploy requests.
pkg/engine/planetscale/branch.go Calls DisableAutoApply after deploy request creation and fails closed if it can’t be disabled.
pkg/engine/planetscale/branch_test.go Updates tests to assert the new “disable auto-apply” behavior and refusal-on-failure.
pkg/localscale/server.go Registers the LocalScale auto-apply route to match PlanetScale behavior.
pkg/localscale/handlers_actions.go Implements the LocalScale auto-apply handler that flips stored auto_cutover.
pkg/localscale/handlers_deploy.go Treats auto_cutover as optional (pointer) and defaults absent to “on” to emulate remembered defaults.
pkg/localscale/server_integration_test.go Updates integration test helper to disable auto-apply when requesting a held cutover.

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

Comment on lines +548 to +549
e.logger.Info("auto-apply disabled on deploy request; the drive is the sole cutover actor",
"organization", org, "database", database, "deploy_request", dr.Number, "branch", branchName)
Comment on lines +222 to +225
// handleAutoApplyDeployRequest turns a deploy request's auto-apply on or off.
// It is the only way a client can state that a deploy request must hold at
// pending_cutover instead of cutting over on its own, because the create
// request's auto_cutover field cannot carry a false.
Comment on lines +545 to +547
if err := client.DisableAutoApply(ctx, org, database, dr.Number); err != nil {
return nil, fmt.Errorf("deploy request %d was created but auto-apply could not be turned off, so PlanetScale may cut over without SchemaBot: %w", dr.Number, err)
}
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