Skip to content
Latchkey

How to Detect Schema Drift in GitHub Actions

Drift means the schema and the committed migrations disagree; CI catches it by diffing the migrated database against the model and failing on any difference.

After applying migrations, ask the tool whether the model would generate further changes. A non-empty diff means someone changed the model without adding a migration. Prisma exposes migrate diff --exit-code; Django uses makemigrations --check.

Steps

  • Apply committed migrations to a throwaway database.
  • Diff the model against the migrated schema with --exit-code.
  • Fail the job when the diff is non-empty.

Workflow

.github/workflows/ci.yml
steps:
  - uses: actions/checkout@v4
  - run: npm ci
  - run: npx prisma migrate deploy
    env: { DATABASE_URL: postgres://postgres:postgres@localhost:5432/app_test }
  - name: Fail on schema drift
    run: |
      npx prisma migrate diff \
        --from-url "$DATABASE_URL" \
        --to-schema-datamodel prisma/schema.prisma \
        --exit-code
    env: { DATABASE_URL: postgres://postgres:postgres@localhost:5432/app_test }

Gotchas

  • prisma migrate diff --exit-code returns 2 when there is a diff; treat any non-zero exit as drift.
  • For Django, python manage.py makemigrations --check --dry-run fails when model changes lack a migration.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →