The query returned fast, but the schema was wrong. You needed a new column.
Adding a new column sounds simple. In production, it can be a minefield. Schema changes touch live data, break services, and ripple through APIs. The right approach keeps downtime near zero and migrations safe.
First, define the new column in code, not in an ad-hoc SQL script. Use versioned migrations so every change is tracked. In most frameworks, that means creating a migration file that adds the column with a default value or allows nulls. This prevents blocking writes during deploy.
Next, deploy the migration separately from the code that uses it. This two-step deploy lets the database accept the new column in the background before your app writes to it. For large tables, add the column without constraints. Then backfill data in small batches. Avoid locking the table.