The migration broke at 3:17 a.m., and the logs pointed to one cause: no new column in the production table.
Adding a new column to a database table should be simple. In practice, it collides with schema dependencies, query performance, and live traffic. Whether you work with PostgreSQL, MySQL, or a distributed SQL engine, the wrong approach can lock tables, drop indexes, or cause deadlocks. The right approach minimizes downtime, preserves data integrity, and keeps deployments predictable.
Plan the schema change before you touch production. Define the new column with exact data types and constraints. Avoid arbitrary defaults unless required, since they can trigger full table rewrites. For high-traffic services, use batched migrations or background schema change tools to prevent blocking queries. In PostgreSQL, ALTER TABLE ... ADD COLUMN with a NULL default is fast, but adding a NOT NULL with a default forces a full rewrite. In MySQL, online DDL can help, but versions matter—test in staging first.