The schema was stable for months. Then a feature request dropped, and you had to add a new column.
Adding a new column to a database table sounds simple. In production, it’s not. Schema migrations carry risk: locking tables, slowing queries, or breaking downstream services. The wrong change in the wrong window can take your system offline.
First, define the purpose of the column. Avoid generic names. Use clear, specific identifiers that align with your data model. Decide if it should allow NULL, have a default value, or be indexed. These choices affect performance and integrity as soon as the migration runs.
Run the migration in a controlled environment. In PostgreSQL, use ALTER TABLE ... ADD COLUMN with defaults handled in separate steps to prevent table rewrites. In MySQL and MariaDB, check the engine’s online DDL capabilities before deployment. For large datasets, consider adding the column without a default first, then backfilling in batches to avoid downtime.