The code froze. Tests passed yesterday, but now the schema is broken. The problem? You need a new column.
Adding a new column should be fast. In production, it’s often risky. You have to consider migration time, locking, null defaults, index impact, and backward compatibility. A careless ALTER TABLE can block writes for minutes and cause downtime.
The safest path is to design the migration in stages. First, add the new column with a nullable default to avoid rewriting existing rows. Then backfill data in small, controlled batches. Finally, update the application code to use the new field, and only after that, enforce constraints or indexes if needed.
Every database engine behaves differently. PostgreSQL handles ADD COLUMN with a default efficiently if the default is constant. MySQL may still rewrite data and lock the table, so you may need tools like pt-online-schema-change for zero-downtime migrations. For large datasets, break the process into steps that can be rolled back at each stage.