The database schema was locked, and the migration had to run now. You needed a new column.
Adding a new column sounds simple, but in production systems, it’s a decision that impacts performance, code, and data integrity. Whether you’re working with PostgreSQL, MySQL, or a cloud-native database, understanding the correct way to add and manage a new column can prevent downtime and data loss.
A new column changes the shape of your table. Adding it directly in a migration is the common path. In PostgreSQL:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
In most cases, adding a nullable column is fast. But for high-traffic writes, even an ALTER TABLE can lock rows or the whole table. On large datasets, choose options that apply changes in smaller batches, or use tools like pg_online_schema_change or gh-ost for MySQL.
If the new column must be non-null, add it as nullable first, backfill in small chunks, and then apply the NOT NULL constraint. This staged approach avoids full-table locks and keeps services live.