The schema changed last night, but no one changed the migration. You need a new column.
Adding a new column should be fast, predictable, and safe. Yet it’s where many systems break. Schema drift, partial deploys, and downtime cause delays. Data integrity suffers when column definitions are unclear or inconsistent. The goal is zero surprises from the first deploy to production.
Start with intent. Name the column for what it stores. Use types your database handles natively. Avoid implicit conversions. If it’s nullable now but won’t be later, plan that migration path before the first deploy.
In Postgres, the most reliable pattern is:
- Add the column without constraints.
- Backfill data in small batches.
- Add constraints or indexes only after the data is ready.
For MySQL, watch for table locks on large datasets. Use ONLINE algorithms where possible. In both systems, test migrations in staging with production-size data. Benchmark the add-column operation to predict time cost.