Adding a new column in production is never just a single command. It touches schema design, migration safety, indexing, null handling, and deploy strategy. The wrong step can lock tables, block writes, or corrupt data.
Start with schema definition. Decide the column name and data type. Keep names short, clear, and consistent with existing conventions. Use the smallest data type that fits the data to reduce storage and speed queries.
Plan the migration. For large tables, run online migrations to avoid downtime. Tools like pt-online-schema-change or native database features such as PostgreSQL’s ALTER TABLE ... ADD COLUMN with NOT NULL DEFAULT can be dangerous on big datasets. Instead, add the column nullable, backfill in small batches, then apply constraints.
Handle backfill carefully. Run idempotent scripts. Monitor replication lag if you use read replicas. Write logs for rows updated. Use transaction boundaries that won’t blow out locks.