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.
Postgres locking patterns: SELECT FOR UPDATE, NOWAIT, SKIP LOCKED, advisory locks, application locks, deadlock retry.
Cheatsheet: generated tsvector, websearch_to_tsquery, ts_rank, headline snippets, trigram hybrid.
LISTEN/NOTIFY patterns: real-time event delivery, queue wake-up, payload limits, and combining with the outbox pattern.
Cheatsheet: row locking, NOWAIT, SKIP LOCKED queue, advisory locks (session and tx scoped).
Postgres declarative partitioning via SQLAlchemy: range/list/hash partitions, pg_partman automation, indexes per partition.
Cheatsheet: NOTIFY from a transaction, listen via asyncpg, outbox + LISTEN wake-up pattern.
Postgres RLS for multi-tenant SQLAlchemy: defining policies, setting tenant context per request, and integration with FastAPI.
Cheatsheet: enable RLS, write policies, set tenant per request, application role without BYPASSRLS.
Postgres-specific bulk operations: ON CONFLICT, RETURNING, bulk insert via execute, asyncpg COPY for huge data.