The database was choking. Queries stalled. The fix was a new column.
Adding a new column is not just schema change. It is a contract update between data and the code that calls it. Done wrong, it breaks production. Done right, it unlocks features, speeds up development, and keeps data clean.
First, define the exact data type. Avoid generic types that waste space or slow down lookups. Use INT only when range fits. Use VARCHAR with length limits that match real values. Store time in UTC. Keep nullability explicit.
Plan migrations for zero downtime. In PostgreSQL, ALTER TABLE ADD COLUMN is fast for metadata-only changes, but adding defaults or constraints can lock the table. Split steps:
- Add the column without default.
- Backfill in batches.
- Add constraints after data is consistent.
In MySQL, large tables need special care. Use tools like pt-online-schema-change or native ALTER TABLE ... ALGORITHM=INPLACE when supported. Avoid schema changes during peak load.