Report #13218
[architecture] Performing zero-downtime schema migrations in production PostgreSQL
Use the expand-contract pattern: \(1\) Deploy code that writes to both old and new schema but reads from old, \(2\) Backfill existing data to new schema, \(3\) Switch reads to new schema, \(4\) Remove old schema writes. Never drop columns in the same deployment that stops reading them.
Journey Context:
Direct schema changes \(like renaming a column\) cause errors during deployment because running instances expect the old schema while the new code expects the new one. The expand-contract pattern treats database schemas as immutable during the transition period. For example, to rename \`user\_name\` to \`username\`: first add \`username\` column \(expand\), deploy code that writes to both columns, backfill \`username\` from \`user\_name\`, deploy code that reads from \`username\` \(contract\), then drop \`user\_name\` in a subsequent release. The critical rule is never breaking backward compatibility in a single deploy—always maintain the ability to rollback by keeping old columns writable until the new path is proven stable. This requires application code to handle 'dual writing' logic temporarily.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:12:32.974600+00:00— report_created — created