63 lines
1.7 KiB
YAML
63 lines
1.7 KiB
YAML
name: Database Schema Check
|
|
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- 'prisma/**'
|
|
- '.github/workflows/schema-check.yml'
|
|
|
|
jobs:
|
|
schema-check:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Validate Prisma schema
|
|
run: npx prisma validate
|
|
|
|
- name: Format Prisma schema
|
|
run: npx prisma format --check
|
|
|
|
- name: Generate Prisma Client
|
|
run: npx prisma generate
|
|
|
|
- name: Check for migration drift
|
|
run: |
|
|
# This checks if schema.prisma matches the current migrations
|
|
# If there are changes without migrations, this will fail
|
|
npx prisma migrate diff \
|
|
--from-schema-datamodel prisma/schema.prisma \
|
|
--to-schema-datasource prisma/schema.prisma \
|
|
--script > migration-diff.sql
|
|
|
|
if [ -s migration-diff.sql ]; then
|
|
echo "Schema changes detected without migration!"
|
|
echo "Run 'npx prisma migrate dev' to create a migration"
|
|
cat migration-diff.sql
|
|
exit 1
|
|
fi
|
|
continue-on-error: true
|
|
|
|
- name: Comment PR with schema changes
|
|
if: failure()
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: '[WARN] Schema changes detected. Please generate a migration with `npx prisma migrate dev`'
|
|
})
|