Adding a new column to a database table sounds simple. It isn’t, not when uptime, data integrity, and deployment speed matter. Bad migrations block writes, lock tables, and cause replication lag. Done right, a schema change is invisible to the user and safe for production.
Start by defining the new column with the correct data type and constraints. Match the domain of the column to its actual use. A BOOLEAN that stores flags. A TIMESTAMP WITH TIME ZONE for events, never local time. Use NOT NULL only if defaults are in place. Avoid triggers or functions in the initial deployment; keep the change atomic.
For large tables, add the new column as NULL first. Then backfill in small batches. This avoids long locks and high I/O spikes. Use an indexed approach if queries will filter by the new field, but never build the index in the same migration if the table is large—build it after the backfill is complete.