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 also10
Seed Data
Initial content created programmatically to make an empty system usable or demonstrable.
Data & Content14 connections
Continuous Deployment
Automatically releasing every change that passes validation.
Version Control & Delivery18 connections
Schema Drift
Divergence between a schema and the code, types, or documentation that describe it.
Data & Content16 connections
Write-Ahead Logging
Recording the intent of a change durably before applying it, so a crash can be recovered.
Computation & Algorithms20 connections
Relational Database
Data organized as tables with declared relationships, queried declaratively and guarded by constraints.
Data & Content21 connections
Idempotence
The property that performing an operation twice has the same effect as performing it once.
Systems & Tooling34 connections
Hash Table
A key-value structure that uses a digest of the key to index an array of buckets.
Computation & Algorithms23 connections
Determinism
The property that identical inputs produce identical outputs, and the foundation of caching and verification.
Systems & Tooling61 connections
Object-Relational Mapping
A library that lets code treat database rows as ordinary objects, saving a great deal of boilerplate at the cost of hiding the queries that actually run.
Data & Content9 connections
Schema Evolution
Changing the shape of stored or transmitted data without breaking the old readers and writers that still expect the previous shape.
Data & Content9 connections
Linked from17
- Backward CompatibilityVersion Control & Delivery
Keeping new versions working with old code, data, and clients, the extreme lengths platforms go to preserve it, and the accumulated cost of never being allowed to change.
- Blue-Green DeploymentVersion Control & Delivery
Running two identical production environments and switching traffic between them instead of upgrading one in place.
- Continuous DeploymentVersion Control & Delivery
Automatically releasing every change that passes validation.
- Database ConstraintData & Content
Rules declared in the schema that the database itself enforces on every write, such as uniqueness, required values, and allowed ranges, so bad data is refused at the door rather than cleaned up later.
- Filesystem SnapshotSystems & Tooling
A point-in-time, near-free copy of a filesystem's state, made possible by sharing unchanged blocks with the live data.
- Foreign KeyData & Content
A column that points at a row in another table, with the database refusing any change that would leave the pointer dangling.
- IdempotenceSystems & Tooling
The property that performing an operation twice has the same effect as performing it once.
- Object-Relational MappingData & Content
A library that lets code treat database rows as ordinary objects, saving a great deal of boilerplate at the cost of hiding the queries that actually run.
- Relational DatabaseData & Content
Data organized as tables with declared relationships, queried declaratively and guarded by constraints.
- RollbackVersion Control & Delivery
Reverting a running system to a previous known-good version, as distinct from fixing forward.
- Rolling ReleaseSystems & Tooling
A distribution model that ships updates continuously instead of in versioned batches, trading stability for currency.
- Schema DriftData & Content
Divergence between a schema and the code, types, or documentation that describe it.
- Schema EvolutionData & Content
Changing the shape of stored or transmitted data without breaking the old readers and writers that still expect the previous shape.
- Seed DataData & Content
Initial content created programmatically to make an empty system usable or demonstrable.
- Staging EnvironmentTesting & Verification
A copy of production where changes are deployed and checked before they reach real users, and why the differences between staging and production keep letting bugs through.
- Web StorageWeb Platform
The browser's built-in ways to keep data on the user's device, from the simple string store localStorage to the transactional database IndexedDB, and their limits on size, persistence and security.
- Zero-Downtime DeploymentVersion Control & Delivery
Deploying a new version while the service keeps serving every request, with no maintenance window.