Skip to content

ci(neon): preview migrate, PR schema diff, production migrate on merge - #74

Merged
Skeyelab merged 3 commits into
masterfrom
feat/neon-workflow-migrate-and-diff
Mar 24, 2026
Merged

Skeyelab merged 3 commits into
masterfrom
feat/neon-workflow-migrate-and-diff

Conversation

@Skeyelab

Copy link
Copy Markdown
Member

Summary

Brings .github/workflows/neon_workflow.yml closer to Neon’s automated branching guide:

  • Preview PRs: After creating the Neon preview branch, run yarn db:migrate against the preview DATABASE_URL (committed migrations under db/migrations/ only — no db:generate in CI so deploys stay repeatable).
  • PR comments: Enable neondatabase/schema-diff-action@v1 with pull-requests: write on the create job.
  • On merge: When a PR is merged, check out the merge commit and run yarn db:migrate with secrets.DATABASE_URL (production). When a PR is closed without merge, only the preview branch is deleted.

Repo setup

  • Ensure DATABASE_URL is set in Actions secrets for the primary/production database (same as Neon’s guide).
  • NEON_API_KEY / NEON_PROJECT_ID should already exist from the Neon GitHub integration.

Verification

  • yarn lint, yarn test:run, and yarn build passed locally before push.

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.
Copilot AI review requested due to automatic review settings March 24, 2026 19:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:push to committed-migrations db:migrate.
  • Enable neondatabase/schema-diff-action@v1 PR comments (adds pull-requests: write permission).
  • On PR merge (closed + merged), run yarn db:migrate against secrets.DATABASE_URL (production).

Comment on lines 87 to 92
- 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 }}

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +97
- name: Checkout
if: github.event.pull_request.merged == true
uses: actions/checkout@v4

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
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.
@Skeyelab
Skeyelab merged commit d539560 into master Mar 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants