The table sat there, complete but wrong. You knew the schema was missing something, and the fix was clear: a new column.
Adding a new column to a database table should be simple, but each environment has its own risks. Downtime, migration speed, data integrity—get them wrong, and you pay later. In relational databases like PostgreSQL, MySQL, and MariaDB, the ALTER TABLE command adds a column without rewriting the entire table if the new field allows null values or has a default. But as soon as you add constraints, indexes, or backfill large datasets, the operation can lock the table and block writes.
In PostgreSQL, use:
ALTER TABLE users ADD COLUMN last_login TIMESTAMPTZ;
Adding NOT NULL without a default will fail if existing rows don’t meet the constraint. If you need to backfill data, do it in batches to avoid long transaction locks.
In MySQL, the engine determines how costly an ALTER TABLE is. InnoDB allows instant addition of certain column types in recent versions, but older setups may rebuild the table. Always check ALTER TABLE ... ALGORITHM=INSTANT where possible to keep operations online.