Database Migration
A versioned, ordered change to a database schema, applied once and recorded.
A database migration is a versioned script that changes a schema, applied in order and recorded so it runs exactly once per environment. Migrations are how a schema evolves without anyone hand-editing production.
The discipline has a few unforgiving rules, most of which are learned by violating them.
A migration that has run anywhere is frozen. Editing or renaming it does nothing to the environments that already recorded it, so their schema no longer matches any file. Changes must be appended.
Order is the whole mechanism, and ordering is by name. An appended migration must sort into the right place — and if the sequence includes a data-seeding step, a schema addition must sort before it, because a data layer's insert typically names every column in its current model and a fresh environment will fail on a column that does not yet exist.
Reversal is often a lie. A down migration that deletes data cannot distinguish seeded data from authored data, so refusing to run is more honest than guessing. And bulk deletion inside a migration transaction can hang indefinitely rather than failing.
The only verification that proves any of this is running the real path: reset, migrate, build, start in production mode, and request the result.
See also5
Hand-picked in the note itself — the neighbours worth reading next.
Relational Database
Data organised as tables with declared relationships, queried declaratively and guarded by constraints.
Data & Content8 connections
Seed Data
Initial content created programmatically to make an empty system usable or demonstrable.
Data & Content6 connections
Continuous Deployment
Automatically releasing every change that passes validation.
Version Control & Delivery9 connections
Idempotence
The property that performing an operation twice has the same effect as performing it once.
Systems & Tooling12 connections
Schema Drift
Divergence between a schema and the code, types, or documentation that describe it.
Data & Content9 connections
Linked from5
Notes elsewhere in the wiki that reach for this one.
- Continuous DeploymentVersion Control & Delivery
Automatically releasing every change that passes validation.
- IdempotenceSystems & Tooling
The property that performing an operation twice has the same effect as performing it once.
- Relational DatabaseData & Content
Data organised as tables with declared relationships, queried declaratively and guarded by constraints.
- Schema DriftData & Content
Divergence between a schema and the code, types, or documentation that describe it.
- Seed DataData & Content
Initial content created programmatically to make an empty system usable or demonstrable.