The migration failed halfway. The logs pointed to a missing field. Minutes later, the fix was clear: a new column.
Adding a new column sounds simple. In production, it is where schema design meets deployment risk. The wrong ALTER TABLE can lock rows, stall queries, or block writes. The right approach keeps the database online, the data consistent, and the change invisible to users.
First, define the purpose of the new column. Know the data type, default values, constraints, and whether it will be nullable. This prevents downstream issues with inserts and updates. Use the database’s native ALTER TABLE syntax, but be aware of the engine’s implementation details.
In PostgreSQL, adding a nullable column without a default is instant. Adding one with a default rewrites the table before version 11, but later versions optimize this. In MySQL, adding a column can lock the table unless you use ALGORITHM=INPLACE or a tool like pt-online-schema-change. In distributed SQL systems, schema changes may propagate asynchronously, so test the rollout path.