The migration broke at 2:14 a.m. The log pointed to a missing field. The schema needed a new column.
Adding a new column sounds simple. It isn’t. Every database change touches code, queries, indexes, and integrations. Done wrong, it locks tables or stalls deployments. Done right, it scales without anyone noticing.
First, define the column in the migration script. Use clear, precise naming aligned with your schema conventions. Stick to the correct data type. Avoid nulls unless you need them. Set defaults where possible to keep inserts fast and predictable.
Second, deploy in stages. Add the column with an online migration if your database supports it. For PostgreSQL, use ADD COLUMN paired with concurrent index creation to avoid locks. For MySQL, ensure you run a non-blocking alter via tools like pt-online-schema-change or native async DDL in newer versions.