A schema change had just shipped, and the database was already sweating. The feature needed one thing: a new column.
Adding a new column sounds simple. It isn’t. In production, the wrong migration strategy can lock tables, block writes, and spike latency. The goal is a schema migration that is both safe and fast.
Start by checking your database engine’s capabilities. Some engines allow adding a nullable column or a column with a default without rewriting the whole table. Others require a table copy under the hood. Understand the exact behavior before touching production.
Plan the migration in steps. If the column has a default value or a NOT NULL constraint, consider adding it as nullable first, then backfilling data in small batches. Once data is consistent, add constraints in a separate migration. This prevents full-table locks and reduces risk during deploys.
Use feature flags to decouple code changes from schema changes. Deploy the database migration first, then deploy the application code that writes and reads the new column. This ensures old code won’t throw errors if the schema is not yet ready.