Adding a new column to a database table should be simple, but in production, simple can still break things. The wrong migration can lock your table, kill performance, or corrupt data integrity. The right migration is precise, tested, and executed with zero downtime.
Before you add a new column, define its purpose. Know its data type, constraints, and default values. Choose names that are consistent with your data model. Avoid nullable columns unless required—null logic multiplies complexity. If you need to backfill data, decide whether that happens inline with the migration or in a separate job.
In relational databases like PostgreSQL and MySQL, adding a column without a default often executes instantly. Adding a column with a non-null default can rewrite the whole table, which can lock writes. In large datasets, that means downtime. Plan accordingly. Use ALTER TABLE ... ADD COLUMN with a default only if you know the operation will be fast enough. Otherwise, split the migration into multiple steps: add the column as nullable, backfill in batches, then change it to non-null.