The query returned fast. But the team still needed one thing: a new column.
Adding a new column sounds simple. It is not. Schema changes can stall deployments. They can lock tables during peak load. They can trigger cascading effects across queries, indexes, ETL jobs, and dashboards. Doing it wrong can cripple a system.
A new column begins in the migration script. Define the name, type, constraints, and default values. Avoid defaults that force a full-table rewrite unless that rewrite is planned. Use NULL where safe to preserve speed. If the table is large, run the migration in a phased approach. Add the column first. Populate it in background batches. Switch application logic once the data is ready.
In PostgreSQL, ALTER TABLE ADD COLUMN is instant for nullable fields without defaults. In MySQL, depending on storage engine and version, it might copy the table. Test the migration in staging with production-size data. Measure how long it locks writes. Watch for triggers, foreign keys, and dependent views.