The database was ready for launch, but one field was missing. You needed a new column.
Adding a new column sounds simple, but the wrong approach can lock tables, slow queries, or even take your app offline. The key is to pick a migration strategy that works for your data size, uptime needs, and deployment workflow.
In SQL, ALTER TABLE is the direct way to add a column. For small tables, it’s fast and safe. For large datasets, a blocking alter can cause downtime. Many engineers use tools like pt-online-schema-change or gh-ost to create a new table structure in the background and swap it in with minimal disruption.
When defining a new column, choose the right data type from the start. Changing it later can be costly. If you need a default value, be aware that adding a non-null column with a default can rewrite all rows in some databases. This can be avoided by adding the column as nullable first, then backfilling in batches, and finally updating constraints.