The table was perfect until the spec changed. Now it needs a new column.
Adding a new column is simple in concept but dangerous in execution. Bad migrations block deploys, burn time, and risk data loss. Good migrations are fast, safe, and reversible. The difference is how you plan, run, and verify them.
First, define the new column with clear constraints. Decide on type, nullability, defaults, and indexing before writing code. For large datasets, think about adding the column without locking the table. Use online DDL tools when your database supports them.
Next, apply the schema change in a migration that can run in production without downtime. Avoid adding NOT NULL constraints with defaults in the same step on big tables. Add the column as nullable first, backfill in batches, then enforce constraints in a final pass. This approach keeps writes and reads operational at all times.