A schema change just landed, and the requirement is clear: you need a new column. Not later. Now. The code is live. The data is growing. The migration must be fast, safe, and reversible.
Adding a new column to a production database is not a trivial task. The wrong approach can lock tables, block writes, or degrade performance. Whether you use PostgreSQL, MySQL, or another relational database, the process demands precision.
First, define the column name and data type. Keep it atomic and consistent with existing schema conventions. Avoid nullable columns unless necessary—null handling can complicate queries and indexes. When adding a non-nullable column to a large table, use a default value that does not trigger a full-table rewrite.
Next, plan the deployment. In PostgreSQL, ALTER TABLE ADD COLUMN is fast if no default or constraint is applied immediately. Apply constraints and indexes in separate steps to reduce lock times. In MySQL, be aware of the storage engine. InnoDB supports instant column addition for some operations, but older versions may require full table copies.