Adding a new column should be simple, but the wrong approach can lock tables, slow queries, or break production. Done right, it can roll out safely, with zero downtime, and set the stage for faster features.
Start by defining the purpose of the new column. Know the data type, default value, and whether it can be nullable. Every decision here shapes migration speed and runtime performance.
For relational databases like PostgreSQL and MySQL, adding a column with a default value can rewrite the entire table. To avoid this, create the new column as nullable first, backfill data in small batches, then apply constraints or defaults in a separate step. This pattern reduces locks and avoids blocking writes.
Version your schema changes. Use migration tools that track each step, verify success, and roll back cleanly on failure. Commit these changes to source control alongside the code that depends on them. This keeps deployments atomic and reproducible.