The database table was ready, but the data model wasn’t. You needed a new column, and you needed it without breaking production.
Adding a new column is a common operation, but mistakes compound fast. Schema changes can stall deployments, lock tables, or cause silent data loss if mishandled. Whether your system runs Postgres, MySQL, or a distributed database, precision matters.
First, define the column with the correct type and constraints. Decide if it should allow NULLs. Adding a NOT NULL column without a default will fail unless the table is empty. If you must backfill, consider phased deployment:
- Add the column as nullable.
- Backfill in smaller batches to avoid long locks.
- Enforce NOT NULL after data is stable.
For large tables, use tools like gh-ost or pg_repack to apply changes online. On cloud-managed databases, confirm whether schema changes are online or blocking. Always run the migration in staging against real-size data to see the impact.