The query returned fast, but the schema had shifted. You need a new column, and you need it without breaking production.
Adding a new column in a database is simple in syntax but complex in impact. The wrong decision can lock tables, trigger downtime, or corrupt data. The right process keeps deployment atomic, safe, and reversible.
First, define the column precisely. Name it in a way that makes future joins and queries unambiguous. Choose the smallest data type that fits the data. Enforce nullability and defaults only when necessary.
Next, add the new column in a non-blocking migration. In PostgreSQL, ALTER TABLE ADD COLUMN is typically fast, but can still cause issues in large tables if combined with default values. Add the column without defaults, backfill in small batches, then apply constraints in a follow‑up migration. In MySQL, avoid heavy locks by ensuring the operation is online or using tools like pt-online-schema-change.