Adding a new column sounds simple. In production, it is not. Schema changes can lock tables, trigger full table rewrites, or break application code. A single careless migration can block writes and drop your SLA. The goal is safe, zero-downtime column creation.
First, decide the column type and default. In many databases, adding a column with a non-null default rewrites the table. This is slow. Instead, add it as nullable, then backfill values in controlled batches. This keeps locks short and avoids blocking traffic.
Next, plan the migration strategy. Use feature flags to roll out code that reads the column only after the schema change completes. Write operations to the column only after backfill. This ensures code and data stay in sync.
For PostgreSQL, use ALTER TABLE ADD COLUMN. Keep it light—no constraints or heavy defaults during the initial add. For MySQL, check if your storage engine supports instant DDL for this operation. For big datasets, use tools like pt-online-schema-change or built-in online DDL.