The migration was live, traffic was flowing, and you realized you needed a new column.
Adding a new column to a production database is simple in theory, but high risk in practice. The wrong approach can cause downtime, lock tables, or break queries. The right approach respects performance, schema consistency, and deployment safety.
A new column starts with a schema change. In SQL, that means using ALTER TABLE with precision:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP NULL;
This command works, but on large datasets it can block reads and writes. Some databases handle this better than others. PostgreSQL can add a nullable column without rewriting the whole table. MySQL may require more care, using tools like gh-ost or pt-online-schema-change for zero-downtime migrations.
Plan for defaults and nullability. Adding a non-nullable column with a default forces a full table rewrite in many engines. For fast, safe changes, first add the column as nullable, backfill the data in batches, then enforce constraints later.