Skip to content

ci(db): fail the build when the Prisma schema and migrations drift apart (#1691) - #1782

Merged
GauravKarakoti merged 3 commits into
GauravKarakoti:mainfrom
ChandanVarshney031:feat/prisma-schema-drift-check
Nov 15, 2026
Merged

GauravKarakoti merged 3 commits into
GauravKarakoti:mainfrom
ChandanVarshney031:feat/prisma-schema-drift-check

Conversation

@ChandanVarshney031

Copy link
Copy Markdown
Contributor

Resolves #1691

Problem

A contributor can change prisma/schema.prisma and forget to commit the matching migration (or the reverse). The mistake only shows up later as a runtime error on a fresh deployment or in the Docker entrypoint's migration step.

Solution

  1. db:check-drift Script: Added "db:check-drift": "prisma migrate diff --from-migrations prisma/migrations --to-schema prisma/schema.prisma --exit-code" to package.json so contributors can verify locally that schema.prisma and migrations stay synchronized.
  2. CI Automation: Updated the prisma-drift-check job in .github/workflows/ci.yml to run npm run db:check-drift against a PostgreSQL 16 container and shadow database (SHADOW_DATABASE_URL), failing the job with an explicit message (::error::Schema drift detected. Run 'npx prisma migrate dev --name <change>' and commit the new migration.) if drift (exit code 2) is detected.
  3. Documentation:
    • Added npm run db:check-drift under Database Setup and Before Submitting checklist in CONTRIBUTING.md.
    • Documented npm run db:check-drift and shadow database requirement in prisma/README.md.
    • Added SHADOW_DATABASE_URL reference in .env.example.
  4. Testing:
    • Added unit test suite tests/prisma-drift-check.test.ts covering script definition, CI job structure, documentation references, and diff exit codes (exit 0 for clean schema, exit 2 for unmigrated drift).
    • Fixed argument count for CircuitBreakerError in src/ai/flows/web3-security-explanations.fallback.test.ts to ensure typecheck passes cleanly.

Acceptance Criteria Verification

  • A schema change without a migration fails CI (exit code 2).
  • A clean branch passes (exit code 0).
  • The check runs in a reasonable time (< 1 minute) and needs no secrets (uses local PostgreSQL 16 service container).
  • CONTRIBUTING.md documents the local command.

@vercel

vercel Bot commented Nov 15, 2026

Copy link
Copy Markdown

@ChandanVarshney031 is attempting to deploy a commit to the Gaurav's projects Team on Vercel.

A member of the Team first needs to authorize it.

@GauravKarakoti
GauravKarakoti merged commit 4c488ed into GauravKarakoti:main Nov 15, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci(db): fail the build when the Prisma schema and migrations drift apart

2 participants