Adding a new column to a database is simple in code, but dangerous in practice. The smallest mistake can lock tables, break queries, or corrupt data. The right approach keeps the system fast, stable, and safe during the change.
First, define the new column in the schema migration. Always make the migration explicit, with clear type definitions and default values. Avoid NULLs unless they are intentional. Use a sensible default or backfill existing rows in the same step.
Second, run migrations in a controlled window. On large tables, a blocking DDL change can freeze your application. Use online schema change tools for MySQL or non-blocking ALTER options in PostgreSQL. Monitor CPU, I/O, and replication lag before, during, and after the change.
Third, update the application layer in phases. Deploy code that writes to the new column but does not read from it immediately. Once the data is populated and verified, switch reads to the new column. This staging prevents null reads and inconsistent results.