The query returned fast. But the data was wrong. The fix was obvious—you needed a new column.
Adding a new column in a database is common, but doing it right can mean the difference between a quick deploy and a production incident. Schema changes must be explicit, atomic, and reversible. A careless ALTER TABLE can lock rows, block writes, and stall your entire service.
Before you create a new column, identify the exact data type, constraints, and default values. In PostgreSQL, a column with a default on a large table can rewrite all rows, causing downtime. For MySQL, adding columns without considering NULLability and indexing can explode storage or cripple performance.
Use migrations that fit your deployment model. In frameworks like Rails, Django, or Prisma, migrations provide consistency, but you still control the sequence. Break risky changes into steps: