The query was running fine until the schema changed. Now you need a new column, and you need it without breaking production.
Adding a new column sounds simple. It isn’t. Done wrong, it locks your table, stalls writes, and triggers incidents. Done right, it’s invisible to the end user and effortless to deploy.
First, define the new column with defaults that avoid unexpected NULLs. In most relational databases, adding a nullable column is instant. Adding a column with a non-null default often rewrites the entire table. For huge datasets, that means downtime. If you need a default, add the column as nullable first. Then backfill in small batches. Finally, set the NOT NULL constraint once the data is ready.
For PostgreSQL, ALTER TABLE ... ADD COLUMN is straightforward, but understand the transaction scope. For MySQL, check whether your engine supports ALGORITHM=INSTANT. In both cases, verify migration behavior in a staging copy with production-like volume before touching real data.