Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
owens1127 committed Nov 13, 2024
1 parent 5096392 commit 27a2102
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 41 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/check-migrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ jobs:
with:
bun-version: 1.1.27

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Check migrations
run: |
bun prisma migrate diff \
bunx prisma migrate diff \
--exit-code \
--from-migrations ./packages/db/prisma/migrations \
--to-schema-datamodel ./packages/db/prisma/schema.prisma \
Expand Down
45 changes: 8 additions & 37 deletions .github/workflows/migrate-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@ name: Apply Preview Database Migrations

on:
workflow_dispatch:
push:

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
env:
DATABASE_PRISMA_URL: ${{ secrets.PREVIEW_DATABASE_PRISMA_URL }}

steps:
- name: Checkout code
Expand All @@ -27,30 +19,9 @@ jobs:
with:
bun-version: 1.1.27

- name: Install dependencies
run: bun install --frozen-lockfile

# 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
- name: Apply Changes
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 }}"
bunx prisma db push \
--schema=./packages/db/prisma/schema.prisma \
--accept-data-loss \
--skip-generate

0 comments on commit 27a2102

Please sign in to comment.