Apply Preview Database Migrations #7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Apply Preview Database Migrations | |
on: | |
workflow_dispatch: | |
jobs: | |
apply-preview-migrations: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:15 | |
env: | |
POSTGRES_USER: user | |
POSTGRES_PASSWORD: password | |
POSTGRES_DB: shadow_db | |
ports: | |
- 5432:5432 | |
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- uses: ./.github/actions/setup-bun | |
# Generate a down migration script back to the current production database, then generate an up migration script to the current branch's migrations directory | |
# This 2-step process allows us to apply our migrations in the same way they will be applied in production | |
- name: Generate Migrations | |
run: | | |
bun prisma migrate diff \ | |
--from-url "${{ secrets.PREVIEW_DATABASE_PRISMA_URL }}" \ | |
--to-url "${{ secrets.DATABASE_PRISMA_URL }}" \ | |
--script > down.sql | |
bun prisma migrate diff \ | |
--from-url "${{ secrets.DATABASE_PRISMA_URL }}" \ | |
--to-migrations "./packages/db/prisma/migrations" \ | |
--shadow-database-url postgres://user:password@localhost:5432/shadow_db \ | |
--script > up.sql | |
- name: Apply Migrations | |
run: | | |
bun prisma db execute \ | |
--file down.sql \ | |
--url "${{ secrets.PREVIEW_DATABASE_PRISMA_URL }}" | |
bun prisma db execute \ | |
--file up.sql \ | |
--url "${{ secrets.PREVIEW_DATABASE_PRISMA_URL }}" |