The query ran in under a second, but the numbers didn’t match. You needed a new column. Not a placeholder. Not a hack. A real, persistent column in the database that would hold exactly what the application demanded.
Adding a new column can seem like a small change. In production, it’s not. It can lock tables, stall writes, and break services. The operation needs planning. It starts with defining the schema change in a migration script. Choose explicit column types. Avoid NULL defaults unless they are intentional. Always set constraints early, before code depends on unbounded data.
In relational databases like PostgreSQL or MySQL, adding a new column with a default value can trigger a full table rewrite. For large datasets, use an online schema change tool or a phased migration. First, add the column without a default. Next, backfill data in batches. Then apply the default and constraints. This avoids downtime and keeps transactions flowing.