Skip to content
Latchkey

How to Gate a Deploy on Migration Success

The deploy must not proceed if migrations fail; wire the rollout to depend on the migration step so a failure halts the release.

If migrations fail but the app still deploys, new code runs against an old schema and errors at runtime. Put migrations in a step or job that the rollout depends on, and let a non-zero exit stop the pipeline before any traffic hits the new version.

Same job: order matters

.github/workflows/ci.yml
steps:
  - name: Migrate (must pass)
    run: npx prisma migrate deploy
    env:
      DATABASE_URL: ${{ secrets.DATABASE_URL }}
  - name: Roll out (only runs if migrate succeeded)
    run: ./deploy.sh

Separate jobs: use needs

.github/workflows/ci.yml
jobs:
  migrate:
    runs-on: ubuntu-latest
    steps:
      - run: npx prisma migrate deploy
  deploy:
    needs: migrate   # skipped if migrate fails
    runs-on: ubuntu-latest
    steps:
      - run: ./deploy.sh

Gotchas

  • A step fails the job by default; do not add continue-on-error to the migrate step.
  • A downstream job is skipped when its needs: target fails, which is what you want here.

Related guides

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