Repository navigation
ci(neon): preview migrate, PR schema diff, production migrate on merge - #74
Conversation
Align Neon workflow with the automated branching guide: apply committed Drizzle migrations on preview branches, post schema-diff comments, and run the same migrate step against production when a PR merges. CI does not run db:generate so deploys stay repeatable from versioned SQL.
There was a problem hiding this comment.
Pull request overview
Updates the Neon GitHub Actions workflow to better align with Neon’s automated branching guidance by applying committed migrations to preview branches, posting schema diffs to PRs, and running production migrations on merge.
Changes:
- Switch preview environment DB changes from
db:pushto committed-migrationsdb:migrate. - Enable
neondatabase/schema-diff-action@v1PR comments (addspull-requests: writepermission). - On PR merge (closed + merged), run
yarn db:migrateagainstsecrets.DATABASE_URL(production).
| - name: Delete Neon Branch | ||
| uses: neondatabase/delete-branch-action@v3 | ||
| with: | ||
| project_id: ${{ vars.NEON_PROJECT_ID }} | ||
| branch: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }} | ||
| api_key: ${{ secrets.NEON_API_KEY }} |
There was a problem hiding this comment.
In this job, the preview branch is deleted before production migrations run. If the delete-branch action fails (e.g., branch already deleted/expired or transient Neon API error), subsequent steps will be skipped (default if: success()), so production migrations won’t run on merge. Consider running production migrations before deleting the preview branch, and/or make the delete step non-blocking (continue-on-error: true) and use if: always() for the migration steps so they still execute when merged.
| - name: Checkout | ||
| if: github.event.pull_request.merged == true | ||
| uses: actions/checkout@v4 | ||
|
|
There was a problem hiding this comment.
The PR description says production migrations should run against the merge commit, but this checkout doesn’t specify a ref. To ensure migrations run with exactly the merged migrations (and not an unexpected default ref), explicitly check out github.event.pull_request.merge_commit_sha (or github.sha if you’ve confirmed it matches the merge commit for pull_request.closed).
Drizzle PgDialect.migrate only compares each migration to max(created_at), so journal "when" values must increase with idx. 0002 had a lower when than 0001, which also left preview branches with an empty or inconsistent history re-running 0000 against inherited schema. Add db/baseline-drizzle-migrations.sql for one-time Neon primary repair and a regression test on journal ordering.
Summary
Brings
.github/workflows/neon_workflow.ymlcloser to Neon’s automated branching guide:yarn db:migrateagainst the previewDATABASE_URL(committed migrations underdb/migrations/only — nodb:generatein CI so deploys stay repeatable).neondatabase/schema-diff-action@v1withpull-requests: writeon the create job.yarn db:migratewithsecrets.DATABASE_URL(production). When a PR is closed without merge, only the preview branch is deleted.Repo setup
DATABASE_URLis set in Actions secrets for the primary/production database (same as Neon’s guide).NEON_API_KEY/NEON_PROJECT_IDshould already exist from the Neon GitHub integration.Verification
yarn lint,yarn test:run, andyarn buildpassed locally before push.