The query ran. The table returned. But the schema was already out of sync. You needed a new column, and you needed it without breaking production.
Adding a new column sounds simple. In practice, it can trigger downtime, lock rows, or cause unexpected type coercion. The steps depend on your database engine, your migration tool, and your deployment strategy.
In SQL, the core syntax is predictable:
ALTER TABLE table_name
ADD COLUMN column_name data_type [constraints];
This works in PostgreSQL, MySQL, and most relational databases. But the impact is not uniform. On large tables, ALTER TABLE can be blocking. PostgreSQL 11+ supports ADD COLUMN with a default value as a metadata-only change if the default is a constant. MySQL may still rewrite tables in some cases, costing precious time.
For zero-downtime migrations, avoid backfilling in a single step. Add the column as nullable, deploy code that populates it in the background, and then add constraints in a separate migration. Use explicit NOT NULL only after all rows are populated.