Database Migrations

The change most likely to cause an outage and least likely to be rehearsed: expand/migrate/contract, backfills, locks, and why a migration and a deploy are one coupled event.

Why Migrations Are the Dangerous Change

Five distinct risks hide under the word "migration", and every one of them scales with data you do not have in staging.

Q · Why is a schema change more dangerous than a code change of the same size, and what exactly is the danger?
Expand, Migrate, Contract

The pattern that makes schema change safe: add the new shape, move to it, and only remove the old shape in a later deploy.

Q · How do I change a schema when two versions of my code are running against it at the same time?
Zero-Downtime Migrations

The techniques that let a schema change land while the service keeps serving — and the engine-specific rules that decide which ones are available to you.

Q · How do I apply a schema change without taking a maintenance window?
A Migration and a Deploy Are One Event

Schema and code version separately but must be compatible continuously, which makes every schema change a two-artifact rollout with a compatibility window.

Q · The migration is in the same pull request as the code. Why is that not the same as them changing together?
Backfills

Moving or computing data across every existing row is a long-running production write workload, and it needs the properties of a job rather than of a migration.

Q · How do I populate a new column across a hundred million existing rows without hurting the service?
Destructive Migrations

Dropping, renaming, truncating and narrowing are the only changes with no rollback — and during a rolling deploy they break the instances that have not been replaced yet.

Q · Why is `DROP COLUMN` dangerous when the column is unused, and what does a safe destructive change look like?