The table was failing. Data was growing, queries were slowing, and the schema needed more than a quick patch. You knew what had to happen: add a new column.
A new column is one of the most common schema changes. It sounds simple—alter the table, add the column, run the migration. In reality, it can be the difference between a graceful deploy and a production incident. The process demands precision.
First, define the column type. Match it to the data’s purpose, not just its current state. Use the smallest type that works. Avoid nullable columns unless necessary to preserve existing logic. Consider default values carefully; adding a default to a huge table can lock it during writes.
Second, evaluate the migration path. For small datasets, a direct ALTER TABLE ADD COLUMN may be fine. On large or high-traffic systems, that same command could block queries for seconds or minutes. Use online migrations or tools like pt-online-schema-change or native database features to avoid downtime.