The migration was live, and the database waited. You needed a new column, not tomorrow, not next sprint—now.
Adding a new column should be fast, predictable, and safe. In SQL, the syntax is simple:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
But the real work is more than a single statement. Schema changes can lock rows, block queries, or fail under load. In production, every second counts. You need a plan that preserves uptime, handles defaults, and keeps queries consistent.
First, decide on the column’s nullability. Nullable columns are easiest to add since they skip the backfill on creation. If you need a default value, consider adding the column as nullable, then running a background job to populate it in batches, and later setting NOT NULL. This avoids long locks on large tables.
Second, test migrations in a staging environment with production-scale data. Measure lock times. Check indexes. A new column can impact query planners if it's indexed or used in joins.