Zero-downtime database migrations: our workflow
We run PostgreSQL for all our primary data. As the schema evolves, migrations have to happen without taking the platform offline. Here is the workflow we use.
The core principle: every migration must be backward-compatible with the previous application version for at least one deployment cycle. This means we deploy in two steps.
**Step 1 — Additive migration.** We add the new column, table, or index. The existing application ignores the new structure. The new application uses it. Both versions can run against the same database.
**Step 2 — Cleanup migration.** Once the new version is fully deployed and stable, a second migration removes the old column or constraint that is no longer needed.
We enforce this with a migration linter in CI that rejects any migration containing a DROP or RENAME without a corresponding additive migration in a prior release.
This has allowed us to run 47 consecutive schema migrations without a maintenance window.