The table was live in production when the request came in: We need a new column.
Adding a new column sounds simple. In practice, it can break queries, slow down writes, stall deployments, or lock entire tables. Schema changes are high-risk operations, and downtime is expensive. Planning matters.
The first step is to define the new column with precision. Specify the data type, nullability, default values, and constraints. Avoid vague requirements that cause multiple migrations. Decide if historical rows will get default values or be backfilled. Large backfills demand more care than small ones.
Next, choose the migration strategy. For small datasets, an ALTER TABLE might be fine. For large datasets, use an online schema change tool to avoid locks. In MySQL, consider gh-ost or pt-online-schema-change. In PostgreSQL, certain changes like adding a nullable column are fast, but adding defaults to big tables may require rewriting the table. Test these operations on staging with realistic data volumes.