The migration was almost done when you realized the schema was wrong. You needed a new column, and you needed it now.
Adding a new column sounds simple. It can be—if you do it right. In SQL, a new column changes the structure of a table. That means it can impact queries, indexes, constraints, and data integrity. The wrong approach can lock tables, block writes, or slow your app to a crawl.
Plan the change before you write it. Define the column name, data type, default values, and nullability. Decide if you’ll allow nulls, set a default value, or backfill data. Always check the size of the table. On massive datasets, adding a new column can be an expensive operation.
In PostgreSQL, a basic example is:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
If you add a column with a default on a huge table, the database might rewrite every row. To avoid downtime, add the column as nullable, then backfill data in small batches, then apply a default and constraint.