Adding a new column sounds simple. In production, it can be dangerous. The wrong command locks tables, blocks writes, and stalls an API under load. The right workflow makes the change without downtime, without risk, and with a clear rollback path.
First, define the column precisely. Set the name, type, and constraints. Avoid nullable columns without defaults unless they serve a clear purpose. Every new column should align with data integrity rules and application logic.
Second, choose a migration strategy. For small tables, a direct ALTER TABLE ADD COLUMN may work. For large datasets, use online schema change tools like pt-online-schema-change or native database features such as PostgreSQL’s ADD COLUMN with defaults computed in a later transaction. This prevents long locks.
Third, update all dependent code paths before deploying migrations to production. ORM models, serializers, validation rules, and API endpoints must be aware of the new column. Test in staging with realistic datasets and concurrency.