Adding a new column sounds simple, but mistakes here ripple through data, code, and production. Whether the database is PostgreSQL, MySQL, or a distributed store, the steps are the same: plan the change, execute with zero downtime, and verify.
First, decide the column’s type and constraints. Choose nullability with care. Adding a NOT NULL column with no default will break existing inserts. Set a default only if it matches real-world data; defaults for convenience can poison a dataset.
Next, consider the size of the table. On large tables, adding a new column with a default value can lock writes for minutes or hours. In PostgreSQL, ADD COLUMN without DEFAULT is fast because it avoids a full table rewrite. For MySQL, use ALGORITHM=INPLACE or ALGORITHM=INSTANT when the engine supports it.
Then, deploy the change in phases. Add the new column as nullable. Release code that writes to both old and new columns if you are backfilling. Once data is synced, run your migration to finalize constraints.