Report #7292
[architecture] Database migrations causing downtime or data loss when adding non-nullable columns, dropping columns, or renaming tables in production
Use the Expand-Contract pattern: \(1\) Expand - add new column/table as nullable or write-only, deploy code that writes to both old and new; \(2\) Migrate - backfill data; \(3\) Switch reads to new schema; \(4\) Contract - remove old column/code.
Journey Context:
Running ALTER TABLE ADD COLUMN NOT NULL on a large PostgreSQL table requires a full table rewrite and exclusive lock, blocking reads/writes for hours. Renaming a column breaks running applications instantly. The expand-contract pattern treats the database schema like an API that must maintain backward compatibility across versions. By supporting both schemas simultaneously during a transition window \(dual-writing\), you avoid any instant where the system is inconsistent. This is the only safe way to handle destructive changes \(renames, type changes\) or additive constraints \(non-nullable columns\). It requires application code to be forward-compatible \(ignore unknown columns\) and careful orchestration of deployment steps, but it guarantees zero downtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:17:26.044413+00:00— report_created — created