Adding a new column sounds simple, but in production it can become a high‑risk operation. The wrong approach locks tables, blocks writes, and degrades performance. The right approach makes the change visible instantly without downtime.
First, define the purpose of the new column. Decide the data type, defaults, and nullability with precision. Avoid excessive flexibility; every constraint you omit now becomes a liability later.
Second, pick the safest migration strategy. In relational databases like PostgreSQL or MySQL, adding a nullable column without a default is usually instant. Adding a column with a default often rewrites the table and locks it. Break this into two steps:
- Add the new column as nullable with no default.
- Backfill data in controlled batches.
Then set the default for new writes.
Third, update the application code. Read logic must handle the absence of old data. Write logic should set the column’s value consistently. Deploy code changes after schema changes are live but before deprecating fallback paths.