The query finished running, but something felt wrong. The schema was correct yesterday. Now the dashboard flagged an unknown field. You open the migration file and see it: time to add a new column.
Adding a new column in a production database is simple in theory and dangerous in practice. Done wrong, it locks tables, slows queries, and risks downtime. Done right, it extends your schema without breaking a single request.
First, understand the context. Identify the table’s size, indexes, and constraints. Review how the new column will interact with existing queries. For high-traffic systems, even reading from a locked table for seconds can cause request failures.
Use an ALTER TABLE statement that works with your database engine’s capabilities. In PostgreSQL, adding a nullable column without a default is fast. Adding a NOT NULL with a default forces a rewrite. MySQL behaves differently depending on storage engine and version. Know the specifics before committing.