The table was growing, but the data didn’t fit. You needed a new column. The schema refused to yield. The migration hung in staging. Production loomed.
Adding a new column sounds small. In code, it’s rarely just SQL. It touches indexes, constraints, triggers, and downstream systems. A new column in PostgreSQL or MySQL can cause locks. In high-traffic environments, those locks can freeze writes. In analytics databases, the wrong column type can double storage costs.
Start with the data type. Choose the smallest type that fits the data. Integers over bigints where possible. Fixed-length strings over unlimited text when you can control size. If nullability matters, define it. Default values should be explicit. Implicit defaults can surprise the application layer when old rows populate during migration.
Deployment matters. For critical systems, use an online schema change tool such as pt-online-schema-change or gh-ost. For PostgreSQL, consider adding the column without a default, then backfilling in batches. Keep each batch small enough to avoid locking. Monitor replication lag during the change.