The task was simple: add a new column. But in production environments, nothing is ever just simple. A poorly planned schema change can lock tables, spike latency, and break code paths you forgot existed.
Adding a new column to a table should begin with clarity. Define the purpose, data type, nullability, default values, and indexing strategy before you touch the database. Avoid unnecessary writes—adding a column with a default value on a large table will rewrite every row, blocking operations. Instead, create the new column nullable, backfill data asynchronously, then enforce constraints.
Different database engines have different behaviors. MySQL and PostgreSQL handle certain ALTER TABLE operations without table locks under specific conditions, but not all. On PostgreSQL, adding a nullable column with no default is fast, but adding with a non-null default can be slow. On MySQL, online DDL features vary by storage engine and version. Always test in staging with production-scale data before applying to main.