The query ran. The table was clean. But the feature you needed demanded one thing: a new column.
Adding a new column seems simple. In production, it’s not. Schema changes touch live data. They can lock tables, slow queries, and create downtime if handled poorly. The key is to plan for safety, backward compatibility, and zero-disruption deployment.
Start with a clear migration path. Decide on the column name, data type, and default value. Keep the operation additive. Adding a new column should not remove or change existing fields. This avoids breaking code paths in older application versions.
If your database supports it, use ALTER TABLE ... ADD COLUMN with a null default to reduce write load. For large datasets, consider adding the column without a default, then backfilling in small batches. Use transactional DDL if possible, but remember some engines like MySQL may lock entire tables. In those cases, switch to online schema change tools like pt-online-schema-change or gh-ost.