Adding a new column seems simple—until it hits production. The wrong migration can lock tables, drop data, or leave indexes useless. The right approach avoids downtime, keeps queries fast, and works across all environments.
First, define the new column in your schema with its type, nullability, and default value. For backward compatibility, avoid adding NOT NULL without a default to large tables. This prevents costly table rewrites.
Second, use online schema change tools when operating on large datasets. In PostgreSQL, ALTER TABLE ... ADD COLUMN is fast if no default is set. In MySQL, consider pt-online-schema-change or gh-ost to avoid blocking writes.
Third, deploy in stages. Ship the change to your development branch. Run migrations in staging with production-like data. Monitor query performance before and after. Any new index tied to the column should be created in a separate migration to reduce lock time.