The migration stopped. The schema was wrong. You needed a new column, and you needed it now.
Adding a new column in a database should be fast, safe, and transparent. Yet it often turns into delayed deploys, broken builds, or silent failures in production. The right approach depends on your database engine, your application’s traffic, and your deployment pipeline.
In SQL, the simplest path is ALTER TABLE. For example:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works for small tables or low-traffic environments. For large datasets, you risk locking rows for longer than your SLA allows. Postgres offers concurrent operations and functions to backfill data in batches. MySQL and MariaDB support ALGORITHM=INPLACE and LOCK=NONE options to reduce downtime.
When adding a new column with default values, beware of automatic backfills that rewrite the entire table. Instead, add the column as nullable, gradually populate it, and then enforce constraints once data is complete. This avoids heavy locks and prevents errors in live queries.