The migration failed five minutes before deploy. The logs showed nothing but a cryptic error: unknown column. You know what that means. A new column was added, but the code and the database are out of sync.
Adding a new column should be simple. It is not. Schema changes carry risk. A single mismatch can break production, lock tables, or drop connections. The correct approach starts with planning. Identify where the new column fits in the schema. Write migrations that are reversible. Ensure default values or null constraints match the application’s logic.
In SQL, adding a new column looks like:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This works in development. In production, you need to think about locks, data backfills, and query performance. A new column on a large table can block writes for seconds or minutes. Mitigate this by adding the column with NULL allowed, then backfilling in batches. Once data is correct, add constraints or defaults.