The table was already in production when the request came in: add a new column without downtime. No excuses, no rollbacks. The data model had to change, and the system had to keep running.
A new column in a database table seems small until you consider constraints, indexes, and live query load. Schema changes in production can lock rows or block reads. The longer the lock, the higher the risk. Every engineer knows the sound of queries piling up.
To add a new column safely, start with the exact SQL migration. In PostgreSQL, for a nullable column without a default, the change is near-instant:
ALTER TABLE orders ADD COLUMN order_status text;
Adding a new column with a default value is slower because it rewrites the entire table. Use a two-step migration: create the column as nullable, then backfill data in batches, and finally set DEFAULT and NOT NULL constraints. This pattern avoids heavy locks.
For MySQL, the performance impact depends on the storage engine and version. InnoDB with ALGORITHM=INSTANT or INPLACE can reduce downtime, but older versions may still lock the table. Always check supported migration algorithms before deployment.