Adding a new column sounds simple. It isn’t, if you care about production data, uptime, and schema integrity. A poorly executed change can lock tables, block writes, or cause migrations to fail. Done right, it’s invisible to the user and safe under load.
The first step: define the column in your migration file with explicit types and constraints. Always set NOT NULL if the data model requires it. Use defaults where needed to prevent inserts from breaking.
Next, decide on deployment strategy. For large tables, a blocking ALTER TABLE is dangerous. Consider online schema changes with tools like gh-ost or pt-online-schema-change. These let you add a new column without downtime by creating a shadow table, migrating data, and swapping in place.
Maintain backward compatibility during rollout. Application code should handle the absence of the new column gracefully until the migration is complete on all replicas. This means feature flags or conditional logic tied to schema version checks.