The migration failed. The logs said one thing; the database told another. Somewhere in the middle, a missing new column broke the deployment.
Adding a new column sounds simple. In production, it can be deadly. Queries slow. Locks hold. Backfills hang. Users feel the lag. The right way depends on your schema, your size, and your uptime budget.
Always start with the schema change plan. Define the new column with the correct type, default, and nullability from the start. Avoid rewrites to massive tables. For large datasets, add the column as nullable first. Populate in small batches. Update constraints in a final step. This prevents locks from stalling transactions.
Use database-specific features. In PostgreSQL, ALTER TABLE ADD COLUMN is fast if it’s nullable without a default. In MySQL, ALTER TABLE can still lock writes—use ONLINE DDL if possible. In MongoDB, a new field requires no schema change, but your application still needs to handle absent keys gracefully.