Migration Mastery Guide

7 lessons for backend developers who ship schema changes to production. Save this page or print it for your team wiki.

📋 Table of Contents

  1. The 5-Minute Schema Review
  2. Zero-Downtime Migration Patterns
  3. The 12 Changes That Break Production
  4. Rollback Strategies That Work
  5. CI/CD Schema Diff Integration
  6. Team Workflows at Scale
  7. Your Migration Safety Checklist
Day 1

The 5-Minute Schema Review

Before every deploy, spend 5 minutes reviewing your schema diff. This simple habit prevents 90% of migration-related outages.

The Checklist

  1. Destructive changes — Are any columns or tables being dropped? If so, confirm nothing depends on them (foreign keys, views, triggers, application code).
  2. Constraint additions — Are you adding NOT NULL or UNIQUE to large tables? These can lock tables for minutes or hours.
  3. Type changes — Is a column being narrowed (e.g., VARCHAR(255)VARCHAR(100))? This can truncate existing data.
  4. Missing indexes — Are new foreign keys created without backing indexes? Unindexed foreign keys cause full table scans on parent updates/deletes.
  5. Default values — Are new columns added without defaults? Existing rows will have NULL values, which may break application logic.

🛠️ Run your schema through SchemaLens — it checks all of these automatically and gives you a risk score.

Pro tip

Don't just review the migration file. Review the diff between the old schema and the new schema. Migration files can be misleading — they show what the developer intended to change, but a semantic diff shows what actually changed.

Day 2

Zero-Downtime Migration Patterns

Not all schema changes require downtime. Understanding which changes are safe and which need special handling is the foundation of reliable deploys.

Safe changes (no special handling needed)

Unsafe changes (require caution)

The expand/contract pattern

For unsafe changes, use the expand/contract pattern:

  1. Expand: Add the new structure while keeping the old one. Example: add email_address column, keep email.
  2. Migrate: Backfill data and update application code to write to both columns.
  3. Contract: After confirming everything works, drop the old column in a later deploy.

📖 Read the complete Zero-Downtime Migration Guide with copy-paste scripts for PostgreSQL, MySQL, SQL Server, and Oracle.

Day 3

The 12 Changes That Break Production

After analyzing thousands of schema diffs, we've identified the changes that cause outages most often. Know these by heart.

  1. Dropping a column — Breaks views, triggers, stored procedures, and application code that reference it.
  2. Dropping a table — Cascades to foreign keys, views, and sometimes ORM models.
  3. Adding NOT NULL without a default — Fails on existing rows or locks the table during validation.
  4. Narrowing a column typeVARCHAR(255)VARCHAR(50) silently truncates data in some databases.
  5. Changing a column typeINTBIGINT is safe; TEXTVARCHAR may not be.
  6. Renaming a column — Breaks every query, view, and procedure that references the old name.
  7. Renaming a table — Breaks foreign keys and ORM mappings.
  8. Dropping an index — Causes query performance regressions that are hard to detect in staging.
  9. Dropping a foreign key — Removes referential integrity protection; orphaned rows accumulate.
  10. Adding a unique constraint on existing data — Fails if duplicates exist; locks the table during validation.
  11. Changing a primary key — Breaks foreign key relationships and often requires table recreation.
  12. Removing a default value — Causes INSERT failures in applications that relied on the database default.

🎯 Test your knowledge — take the Schema Breaking Change Quiz and see how many you can spot.

Day 4

Rollback Strategies That Work

Every migration should have a rollback plan. But not all migrations can be rolled back cleanly.

Reversible changes

Irreversible changes

The rollback script rule

Before running any migration in production, write the rollback script first. If you can't write a rollback script, reconsider the migration. For irreversible changes, take a database backup or snapshot before running the migration.

🔄 SchemaLens Pro generates rollback scripts automatically — reverse ALTER TABLE statements for every migration.

Day 5

CI/CD Schema Diff Integration

The best time to catch a bad migration is before it merges. Automating schema diff in your CI pipeline ensures every change is reviewed.

The GitHub Actions workflow

Add a schema diff step to your CI workflow that compares the schema on the PR branch against the schema on main:

  1. Dump the schema from your main branch (pg_dump --schema-only or mysqldump --no-data)
  2. Dump the schema from the PR branch
  3. Run a diff tool to compare them
  4. Post the diff as a PR comment so reviewers can see what changed

Pre-commit hooks

For teams that want faster feedback, a pre-commit hook can run a local schema diff before the developer even commits. This catches issues in seconds, not minutes.

⚙️ Use the SchemaLens GitHub Action — auto-generates diff reports and posts them as PR comments.

Day 6

Team Workflows at Scale

As teams grow, schema reviews become a bottleneck. The solution isn't to skip reviews — it's to make them faster and more consistent.

The schema change RFC

For large or risky changes, write a one-paragraph RFC that answers:

PR templates

Add a schema review section to your pull request template:

Ownership and alerts

Assign a "schema owner" for each service or domain. This person reviews all schema changes for that domain and is responsible for migration safety. When something goes wrong, they know the schema best.

👥 Book a Team Schema Audit — we'll review your team's migration workflow and recommend improvements.

Day 7

Your Migration Safety Checklist

Print this checklist and use it before every deploy. It takes 2 minutes and prevents hours of incident response.

Pre-deploy checks

Post-deploy checks

View the expanded Migration Checklist — 25 points with detailed explanations for each.

What's next?

You now have the knowledge to ship schema changes safely. The next step is to make the process effortless. SchemaLens Pro automates the diff, risk scoring, and migration generation so you can focus on shipping.