PlanetScale — Declarative schema migrations¶
Summary¶
Short PlanetScale tutorial post by Brian Morrison II
(2023-04-05, re-surfaced via the 2026-04-21 feed snapshot).
The post is the conceptual framing companion to the
same author's 2022-09-16 Atlas-CLI tutorial
(sources/2026-04-21-planetscale-declarative-mysql-schemas-with-atlas-cli):
where the earlier post shows the mechanics of a
declarative workflow (inspect → edit HCL → apply), this
post covers the trade-off space — benefits, drawbacks,
concurrency failure modes, and how PlanetScale's native
branching + deploy-request workflow fits into (or replaces)
the declarative-tool ceremony. Directly links to a
"versioned migrations" sibling post
(/blog/versioned-schema-migrations) as the alternative
approach, positioning this post as half of a
declarative-vs-versioned comparison pair.
Key takeaways¶
-
Declarative schema management is Database-as-Code by direct analogy to IaC — the post opens with an AWS SAM CLI Lambda+API Gateway example ("sam-go-sample"), frames a schema file as "specially-crafted" text the tool can interpret, and presents
atlas schema apply's HCL worked example alongside it. Same DSL family (HashiCorp HCL), same apply-from-Git-commit ceremony. (Source: sources/2026-04-21-planetscale-declarative-schema-migrations) -
Three structural benefits canonicalised: (1) Single Source of Truth — one file is authoritative, the live database is a reconciliation target; (2) Readability over DDL — declarative files are easier for developers to understand than the imperative DDL scripts emitted by versioned-migration tools; (3) CI/CD ergonomics — apply commands are scriptable, so schema rollout integrates into existing deploy pipelines without separate ceremony.
-
Hidden cost: DDL-as-crutch. Canonical verbatim drawback: "While eliminating the need to learn DDL can be a benefit, using tools to circumvent the process of learning may act as a crutch for developers." First wiki articulation of the abstraction-hides-substrate failure mode applied to schema management — engineers who never learn DDL cannot diagnose the tool's emitted SQL when something goes wrong, inverting the democratisation argument.
-
Concurrent-edit failure mode: "If you consider that multiple developers may be making changes to the schema definition files at the same time on separate machines, you may run into a scenario where one developer's changes will overwrite another's, causing conflicts in what the database schema should be." Canonical wiki statement that the single-file model of Schema-as-Code is a Git-merge-semantics-dependent consistency model — two developers with diverged schema.hcl branches cannot both apply to the same database and win; the loser silently discards work. The apply tool has no concept of "desired state from whom".
-
Stateful-data reminder: "databases are inherently stateful, where the data that is stored by the database is just as important as the structure of the database." Canonical framing that declarative tools operate on structure only and must not be trusted with semantic data-migration intent (backfills, type narrowing, rename-vs-drop-add disambiguation) — the patterns/expand-migrate-contract sequencing discipline is explicitly the operator's responsibility, not the tool's.
-
PlanetScale native workflow as rival ceremony — branching + safe migrations + deploy requests is PlanetScale's own form of schema migration, and the post frames this as "a form of schema migration in itself" rather than as a substrate atop which declarative tools run. Safe migrations restrict DDL on protected branches, so declarative tools can only run against development branches where DDL is permitted. Consistent with the 2022-09-16 Atlas post's "disable safe migrations" precondition.
-
Proposed GitOps workflow: dedicated
dbrepository canonicalised as a concrete composition pattern — developers check schema edits into a "dedicated repository (let's call it thedbrepository)", automated tools monitor the repo for changes, apply them to the active development branch, and notify the team that the schema has changed so they can act accordingly. Production cutover is gated by deploy requests for review and approval. First canonical wiki instance of a schema-only monorepo + watcher bot GitOps pattern for declarative schema management. -
Development-cycle cadence implicit: open a new PlanetScale branch "each time code changes are required, typically at the beginning of a development cycle." The branch is the unit of schema iteration; the
db-repo PR is the unit of schema review.
Systems / concepts / patterns extracted¶
- Systems: systems/atlas-cli (referenced via HCL example, not named; the same DSL shape as the 2022-09-16 tutorial), systems/mysql (SQL engine target), systems/planetscale (vendor + branching workflow), systems/aws-lambda (IaC analogue used in the post's introduction), systems/git (authoritative version control for the schema file).
- Concepts: concepts/schema-as-code (DSL file as source of truth), concepts/schema-evolution (declarative-vs-versioned altitude of the same problem), concepts/coupled-vs-decoupled-database-schema-app-deploy (PlanetScale's deploy-request workflow is a decoupled-deploy discipline), concepts/online-ddl (the engine-level primitive any apply step ultimately invokes).
- Patterns: patterns/declarative-schema-management (canonical pattern this post is a conceptual framing post for), patterns/expand-migrate-contract (complementary sequencing discipline mentioned indirectly via the "stateful-data" reminder), patterns/schema-validation-before-deploy (PlanetScale's deploy-request review+approval gate is a vendor-specific instance).
Operational numbers / diagrams¶
- None. Tutorial voice, no production metrics, no
customer telemetry, no cutover latency numbers. AWS SAM
YAML snippet + two Atlas HCL snippets (before/after
adding a
starscolumn) are the only code artefacts. - No comparison tables, no benchmark methodology, no schema-file-conflict recovery playbook.
Caveats¶
- Tutorial voice, not retrospective — Brian Morrison II is writing conceptual developer-education content, not a PlanetScale production war story. No data on how PlanetScale customers actually use declarative tools in practice; no adoption numbers.
- Atlas implicit but not named in the body. The HCL
syntax in the worked example is Atlas's; the
"specially-crafted file that the tool can
understand" phrasing is deliberately tool-agnostic.
The 2022-09-16 tutorial names Atlas explicitly and
shows
atlas schema inspect/atlas schema applycommands; this post is the generalisation. - Proposed
db-repository workflow is aspirational, not shipped — no tool is named for the "automated tools to monitor thedbrepository for changes" step; the pattern is a sketch, not a deployed production system. - Concurrent-edit failure mode is stated, not resolved — the post flags the conflict scenario without proposing a mitigation (no mention of lock files, leader election, branch-per-developer workflows, or merge-then-apply gating). The gap implicitly motivates the deploy-request workflow as the remediation, but this link is not made explicit.
- Versioned-migrations comparison is one-sided — linked but not summarised. Reader is expected to read both posts to see the full trade-off space.
- No discussion of drift detection — the "inspect" primitive that makes declarative tools drift-aware (covered in the 2022-09-16 Atlas post) is absent here; the post frames declarative tools purely as apply-mechanisms, missing their diagnostic value.
- Published 2023-04-05 with PlanetScale's pre- discontinuation branching + deploy-request workflow intact — post references current PlanetScale docs links for branching and deploy requests, both still load-bearing product features at publication time.
Source¶
- Original: https://planetscale.com/blog/declarative-schema-changes
- Raw markdown:
raw/planetscale/2026-04-21-declarative-schema-migrations-f5d7485b.md
Related¶
- patterns/declarative-schema-management — the canonical pattern this post is a conceptual framing companion to.
- concepts/schema-as-code — the database-equivalent- of-IaC concept this post canonicalises via the AWS SAM analogy.
- sources/2026-04-21-planetscale-declarative-mysql-schemas-with-atlas-cli
— sibling 2022-09-16 tutorial by the same author
covering the mechanics (Atlas CLI
inspect+apply) that this post covers at the conceptual / trade-off altitude. - sources/2026-04-21-planetscale-backward-compatible-database-changes — Taylor Barnett's complementary "expand-migrate- contract" pattern post; this post's "stateful data" caveat flags the gap the expand-migrate-contract sequencing discipline fills.
- systems/atlas-cli — the tool whose HCL the worked example uses (referenced implicitly via DSL shape).
- systems/planetscale — the vendor whose native branching + deploy-request workflow the post positions as a form of schema migration in itself.
- systems/aws-lambda — the IaC analogue the post
opens with (SAM CLI, Go
hello-worldfunction + API Gateway deploy). - concepts/coupled-vs-decoupled-database-schema-app-deploy — the deploy-time decoupling PlanetScale's deploy- request workflow enforces.
- concepts/schema-evolution — the broader problem space declarative-vs-versioned is one altitude of.