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. Go to Repository → Actions tab
- 2. Find "Database Management Workflow"
- 3. Click "Run workflow"
- 4. Select "production" environment
- 5. Check "Confirm backup exists"
- 6. Click "Run workflow"
Workflow Configuration
Triggers
.github/workflows/neon_workflow.yml
1on:2 pull_request:3 types: [opened, synchronize] # Show SQL diff4 push:5 branches: [preview] # Auto-apply6 workflow_dispatch: # Manual trigger7 inputs:8 environment:9 type: choice10 options: [production, preview]
Schema Diff
1- name: Generate schema diff2 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_OUTPUT8 env:9 DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }}
Production Safety
1# Require backup confirmation2- name: Verify backup3 if: github.event.inputs.confirm_backup != 'true'4 run: |5 echo "❌ Must confirm backup exists"6 exit 178# Dry run first9- name: Preview changes10 run: pnpm exec prisma migrate diff --script1112# Apply migration13- name: Run migration14 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 devlocally first - • Commit migration files in prisma/migrations/
- • Verify schema.prisma is saved and committed
Next: Database
Schema, queries, and best practices