September 30, 2026

What schema drift is, and how to catch it before it merges

Schema drift is the gap between what your models say and what your migrations did. Where it comes from, why tests miss it, and how to catch it in review.

Every team that uses an ORM lives with two descriptions of its database. The first is the code: models, entities, schema definitions. The second is history: the migration files that actually changed the database. When those two descriptions disagree, you have schema drift.

Where drift comes from

Drift is rarely one dramatic mistake. It accumulates in ordinary work.

  • A migration written by hand. Someone edits the database directly during an incident, writes the migration afterward, and the column type never quite matches the model.
  • A model changed without a migration. A developer renames a field, the tests pass, and the migration folder never finds out.
  • A merge that dropped a migration file. Two branches each add a migration, the second one wins, and the surviving model references a column no migration creates.
  • Defaults added in only one place. The migration sets a default and the model does not, so inserts behave differently depending on which path wrote them.

None of these fail locally. Tests run against a database built from whichever description happened to be consistent that day.

Why tests miss it

Most test suites build their schema from the models, or from a snapshot, not from replaying every migration in order. So the model and the migration history can disagree all the way to production, where the real database was built by replaying migrations and the application was written against the models.

Type checkers cannot see it either. They compare code to code. To them, the migration folder is just text.

Catching drift in review

The fix is a check that compares the two descriptions directly: read the models, read the migration history, and report every disagreement, before the pull request merges.

That check should run from source alone. If it needs a connection to a real database, it becomes another environment to maintain, and it will silently stop running. If it needs CI credentials, it becomes a security review of its own.

Gravitar, our tool for this, works exactly that way: it reads your models and your migration files, reports the disagreements as errors on the pull request, and needs no database or CI credentials. Exit code 1 fails the check, and the drift gets fixed while the change is still open.

A habit, not a tool

Tools catch drift; habits prevent it. Small migrations, one change per migration, and a review question (does the model match what this migration does?) do most of the work. The check exists for the day the habit does not.

If you want this on every pull request without wiring up database access, join the early access list below, or book a pipeline audit and we will help you put it in place.

Gravitar 0.1.0 is released: it catches schema drift before it merges, with no database or CI credentials required.

See Gravitar