The query landed. The schema had to change fast. A new column was the only way forward.
Adding a new column to a database sounds simple. In production, it can be risky. The wrong approach can cause downtime, deadlocks, or performance hits. The right approach keeps services running with zero visible impact to users.
Start with clarity on why the new column is needed. Is it for new features, analytics, or system integration? This defines the column type, defaults, and indexing strategy. Avoid adding columns without clear purpose.
Choose the right migration method. For relational databases like PostgreSQL or MySQL, ALTER TABLE ADD COLUMN is common. But with large datasets, adding a column with a default value can lock the table. Instead, add the column as nullable first, then backfill data in batches. This prevents locks and keeps queries responsive.
Plan for backward compatibility. If APIs or services depend on the schema, deploy code that can handle both old and new versions before the database change. This is critical for zero-downtime migrations.