The database needed a new column, fast.
Adding a new column sounds simple, but the wrong move can lock tables, block writes, and bring down production. In high-traffic systems, a careless migration can cause downtime measured in revenue lost. The key is to plan the change, run it safely, and make sure it scales with demand.
First, define what the new column needs to store. Use the smallest data type that fits the requirement. This saves memory and improves query performance. Decide if the column should allow NULL values or require defaults. Avoid expensive defaults that write to every existing row unless necessary.
Second, choose the right migration strategy. For small datasets, a direct ALTER TABLE may be fine. For large or critical tables, use an online schema change tool like gh-ost or pt-online-schema-change. These tools copy data to a shadow table, apply the schema change, and swap without long locks.