Creating a new column in a production database is simple in theory and dangerous in practice. The wrong SQL can lock tables, block queries, or corrupt data. The right process avoids downtime while keeping schema changes in sync with application code.
Start by defining the new column with a clear schema migration. Use tools like Liquibase, Flyway, or Rails migrations to keep changes versioned and reversible. Always include the correct data type, nullability settings, default values, and constraints. Without these, data integrity and query performance can degrade fast.
In high-traffic systems, run the migration in a non-blocking way. For large tables, avoid direct ALTER TABLE commands that rewrite the full dataset. Instead, create the column with minimal locking, then backfill data in batches. This reduces the risk of transaction deadlocks and user-facing errors.