Adding a new column in a database should be fast, safe, and reversible. Done poorly, it can block writes, lock rows, or corrupt data. Done well, it unlocks new features without downtime.
First, choose the right migration strategy. With SQL databases like PostgreSQL or MySQL, ALTER TABLE ADD COLUMN is straightforward for small tables. On large datasets, online schema changes are critical. Tools like pg_online_schema_change or gh-ost allow you to add columns without locking writes.
Decide on defaults early. Setting a default value on a new column can cause a full table rewrite if not handled carefully. In PostgreSQL, adding a nullable column and then updating in batches avoids performance hits. For MySQL, similar batched updates reduce load spikes.
Consider constraints last. Adding NOT NULL too soon forces a scan on all rows. Fill the column first. Validate the values. Then set the constraint.