Adding a new column is one of the most common database migrations. Yet done carelessly, it can cause outages, performance hits, and production errors. The process must be deliberate, efficient, and safe.
First, define the column name and type with absolute clarity. Choose types that match your data pattern exactly—avoid oversized VARCHARs or vague JSON blobs when a strict type will do. This reduces index bloat and improves query planning.
Second, plan the migration to minimize locking. On large tables, adding a column with a default value can trigger a full table rewrite. Instead, add it as nullable, backfill in batches, then apply constraints when the data is complete.
For PostgreSQL, ALTER TABLE ... ADD COLUMN is fast for nullable fields. For MySQL, watch for the storage engine’s behavior or leverage tools like pt-online-schema-change to avoid downtime. Always run migrations in staging first with production-size data.