Alembic Textbook Ch. 5 — Online Schema Changes (Zero-Downtime Patterns)
Zero-downtime migrations: expand-contract, batched backfills, CONCURRENTLY, NOT VALID FK, and pg_repack.
Zero-downtime migrations: expand-contract, batched backfills, CONCURRENTLY, NOT VALID FK, and pg_repack.
Cheatsheet: when branches form, alembic merge, single-head CI gate, recovery.
Multi-DB migrations via Alembic: -t multidb template, schema-per-tenant strategies, parallelism.
Cheatsheet: multidb template, schema-per-tenant env.py, parallel migrations.
Alembic CI patterns: drift detection, migration round-trip tests, dry-run, deploy gates, and pre-merge checks.
Cheatsheet: GitHub Actions, drift test, up-down round-trip, dry-run SQL, deploy gates.
Production Alembic: deploy strategies, recovery from broken migrations, stamp, manual fixes, and the operational checklist.
Cheatsheet: K8s Job vs app-startup, advisory-lock single runner, forward-only, recovery via stamp.
Cheatsheet: Alembic setup with SQLAlchemy 2.0, env.py for sync/async, naming conventions, common ops.
Cheatsheet: copy-paste migrations for common changes — add NOT NULL column, rename, FK, ENUM, JSONB, view, trigger.