The migration froze halfway. Logs filled with errors. The new column was missing.
Adding a new column to a database table should be simple. In practice, it can be risky, especially in production. Schema changes can lock tables, block reads, or corrupt data if not planned. The key is to handle the operation with precision, minimal downtime, and a clear rollback plan.
When creating a new column in SQL, the most common approach is ALTER TABLE ADD COLUMN. This works for small tables, but on large datasets it can trigger long locks. For high-traffic systems, it’s safer to use an online schema change tool such as pt-online-schema-change or gh-ost. These utilities copy data to a new table with the extra column, then swap it in with near-zero downtime.
Define the new column with the exact data type needed. Avoid adding it as NULL unless you must. If you need a default value, set it in the schema so the database enforces consistency. Populate the column in controlled batches to avoid performance spikes.