A missing column in a live database can stop a release cold. Adding a new column sounds simple, but in production systems it can trigger downtime, lock tables, or break services that expect a certain schema. Precision matters. Speed matters. Safety matters.
When you add a new column, define the exact type and constraints first. Avoid defaults that trigger full table rewrites if the dataset is large. For PostgreSQL, adding a column without a DEFAULT value runs in constant time. For MySQL with InnoDB, adding a new column with a DEFAULT is often an online operation now, but verify with your version. Always run the exact statement on staging before touching production.
Use explicit migrations. Store them in version control. Each migration should be reversible where possible, so you can drop the new column cleanly if the change fails.
ALTER TABLE users ADD COLUMN last_login TIMESTAMP NULL;
If the column will eventually be NOT NULL, first add it as nullable. Backfill in batches with update scripts that don’t overwhelm the database. Then issue a separate migration to enforce NOT NULL. This multi-step path reduces lock times and keeps services responsive.