Adding a new column is one of the most common schema changes, yet it can break production if done wrong. The rules are simple, but the stakes are high. A careless migration can lock tables, slow queries, or crash your app.
Start with the schema definition. In SQL, use ALTER TABLE with clarity. Name the column, set the type, define constraints. Decide if it should allow NULL. If you need default values, set them in the migration file, not in a backfill script that quietly eats hours.
For large datasets, avoid blocking writes. Use online schema change tools like gh-ost or pt-online-schema-change. These utilities create a shadow table, copy rows in batches, then swap it in without downtime. Always test in staging with real data size.
Plan for index changes at the same time. Adding an indexed column can improve performance, but building the index during peak traffic will hit CPU and I/O hard. Schedule index creation during low-load windows, or build it incrementally if your database supports it.