GitHub Actions

Automated database migrations with preview auto-deploy, PR SQL previews, and manual production approval.

How It Works

1

Push to preview

Automatically applies migrations to preview database

2

Pull request

Adds a comment showing the SQL that will execute

3

Production

Manual trigger only — requires backup confirmation

Updating Production

Before you start

  • • Ensure you have a recent backup
  • • Test migration in preview first
  • • Plan for potential downtime
  1. 1. Go to Repository → Actions tab
  2. 2. Find "Database Management Workflow"
  3. 3. Click "Run workflow"
  4. 4. Select "production" environment
  5. 5. Check "Confirm backup exists"
  6. 6. Click "Run workflow"

Workflow Configuration

Triggers

.github/workflows/neon_workflow.yml
1on:
2 pull_request:
3 types: [opened, synchronize] # Show SQL diff
4 push:
5 branches: [preview] # Auto-apply
6 workflow_dispatch: # Manual trigger
7 inputs:
8 environment:
9 type: choice
10 options: [production, preview]

Schema Diff

1- name: Generate schema diff
2 run: |
3 DIFF_OUTPUT=$(pnpm exec prisma migrate diff \
4 --from-schema-datasource prisma/schema.prisma \
5 --to-schema-datamodel prisma/schema.prisma \
6 --script || echo "No pending migrations")
7 echo "diff_output=$DIFF_OUTPUT" >> $GITHUB_OUTPUT
8 env:
9 DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }}

Production Safety

1# Require backup confirmation
2- name: Verify backup
3 if: github.event.inputs.confirm_backup != 'true'
4 run: |
5 echo "❌ Must confirm backup exists"
6 exit 1
7
8# Dry run first
9- name: Preview changes
10 run: pnpm exec prisma migrate diff --script
11
12# Apply migration
13- name: Run migration
14 run: pnpm exec prisma migrate deploy

Troubleshooting

Migration fails

  • • Check GitHub Actions logs for error
  • • Verify DATABASE_URL in GitHub secrets
  • • Ensure preview migration succeeded first

No changes detected

  • • Run pnpm db:migrate dev locally first
  • • Commit migration files in prisma/migrations/
  • • Verify schema.prisma is saved and committed

Next: Database

Schema, queries, and best practices

Continue →