The migration was live, and the schema had no room for error. You needed a new column, and every millisecond mattered.
Adding a new column is one of the most common schema changes in relational databases, yet it’s also one of the easiest places to cause downtime or performance hits. Whether you work with PostgreSQL, MySQL, or MariaDB, the way you add a new column can define the reliability of your deployment.
In PostgreSQL, ALTER TABLE ADD COLUMN is straightforward, but with large tables you must consider locking behavior. Adding a column with a default value will rewrite the entire table, blocking reads and writes. Instead, add the column without a default, then update values in smaller batches. After populating the data, set the default and constraints. This avoids long locks while keeping your migration transactional.
MySQL offers similar options, but ALTER TABLE may still trigger a table copy. With modern versions and ALGORITHM=INPLACE or ALGORITHM=INSTANT (available from MySQL 8.0.12), you can add certain column types instantly without copying the table. Always confirm with SHOW WARNINGS after the ALTER to ensure you didn’t fall back to a costly table rebuild.