The query dropped into the terminal like a command you couldn’t ignore. You needed a new column, and you needed it in production without breaking your schema or your uptime.
Adding a new column sounds simple. It isn’t. The wrong migration can lock tables, stall writes, or blow up indexes. The right approach depends on scale, database type, and the shape of your data.
Start with intent. Name the column with precision. Define its type for how it will be used, not how it feels safe. Avoid NULL defaults if your workload can’t tolerate them. In Postgres, use ALTER TABLE ... ADD COLUMN ... DEFAULT with caution; large defaults can trigger a full table rewrite. In MySQL, watch out for replication lag when altering big tables.
For zero-downtime migrations, break the change in pieces. Add the column without defaults. Backfill data in batches. Then set defaults or constraints once usage is stable. This pattern protects the write path while keeping the schema in sync.