Skip to content

Scheduling infrastructure for absolutely everyone.

feat: add GitHub Action to check Prisma migrations match schema (#26897)

Joe Au-Yeung463987c02d0a
diff --git a/.github/workflows/check-prisma-migrations.yml b/.github/workflows/check-prisma-migrations.yml
new file mode 100644
index 00000000000..3bee03151b8
--- /dev/null
+++ b/.github/workflows/check-prisma-migrations.yml
@@ -0,0 +1,41 @@
+name: Check Prisma Migrations
+on:
+ workflow_call:
+
+env:
+ DATABASE_URL: ${{ secrets.CI_DATABASE_URL }}
+
+jobs:
+ check-prisma-migrations:
+ name: Check migrations match schema
+ runs-on: blacksmith-2vcpu-ubuntu-2404
+ services:
+ postgres:
+ image: postgres:13
+ credentials:
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
+ env:
+ POSTGRES_USER: postgres
+ POSTGRES_PASSWORD: postgres
+ POSTGRES_DB: calendso
+ options: >-
+ --health-cmd pg_isready
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+ ports:
+ - 5432:5432
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ sparse-checkout: .github
+ - uses: ./.github/actions/cache-checkout
+ - uses: ./.github/actions/yarn-install
+ - name: Check if migrations match schema
+ working-directory: packages/prisma
+ run: |
+ npx prisma migrate diff --exit-code \
+ --from-migrations ./migrations \
+ --to-schema-datamodel ./schema.prisma \
+ --shadow-database-url ${{ env.DATABASE_URL }}
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index 6ea81df9b58..552a0e59afd 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -166,9 +166,10 @@ jobs:
permissions:
pull-requests: read
outputs:
- has-files-requiring-all-checks: ${{ steps.filter.outputs.has-files-requiring-all-checks }}
- has_companion: ${{ steps.filter.outputs.has_companion }}
- has-api-v2-changes: ${{ steps.filter.outputs.has-api-v2-changes }}
+ has-files-requiring-all-checks: ${{ steps.filter-exclusions.outputs.has-files-requiring-all-checks }}
+ has-companion: ${{ steps.filter-inclusions.outputs.has-companion }}
+ has-api-v2-changes: ${{ steps.filter-inclusions.outputs.has-api-v2-changes }}
+ has-prisma-changes: ${{ steps.filter-inclusions.outputs.has-prisma-changes }}
commit-sha: ${{ steps.get_sha.outputs.commit-sha }}
run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' }}
db-cache-hit: ${{ steps.cache-db-check.outputs.cache-hit }}
@@ -187,8 +188,9 @@ jobs:
path: backups/backup.sql
key: ${{ steps.cache-db-key.outputs.key }}
lookup-only: true
- - uses: dorny/paths-filter@v3
- id: filter
+ - name: Check for files requiring all checks (with exclusions)
+ uses: dorny/paths-filter@v3
+ id: filter-exclusions
with:
predicate-quantifier: "every"
filters: |
@@ -203,7 +205,12 @@ jobs:
- '!help/**'
- '!apps/web/public/static/locales/**/common.json'
- '!i18n.lock'
- has_companion:
+ - name: Check for specific path changes
+ uses: dorny/paths-filter@v3
+ id: filter-inclusions
+ with:
+ filters: |
+ has-companion:
- "companion/**"
has-api-v2-changes:
- "apps/api/v2/**"
@@ -215,6 +222,9 @@ jobs:
- "packages/trpc/**"
- "packages/prisma/schema.prisma"
- "docs/api-reference/v2/**"
+ has-prisma-changes:
+ - "packages/prisma/schema.prisma"
+ - "packages/prisma/migrations/**"
- name: Get Latest Commit SHA
id: get_sha
run: |
@@ -280,11 +290,11 @@ jobs:
console.log('Found the label?', labelFound);
core.setOutput('run-e2e', labelFound);
- uses: ./.github/actions/yarn-install
- if: ${{ steps.filter.outputs.has-files-requiring-all-checks == 'true' }}
+ if: ${{ steps.filter-exclusions.outputs.has-files-requiring-all-checks == 'true' }}
with:
skip-install-if-cache-hit: "true"
- uses: ./.github/actions/yarn-playwright-install
- if: ${{ steps.filter.outputs.has-files-requiring-all-checks == 'true' }}
+ if: ${{ steps.filter-exclusions.outputs.has-files-requiring-all-checks == 'true' }}
with:
skip-install-if-cache-hit: "true"
@@ -316,6 +326,13 @@ jobs:
uses: ./.github/workflows/api-v2-unit-tests.yml
secrets: inherit
+ check-prisma-migrations:
+ name: Check Prisma Migrations
+ needs: [prepare]
+ if: ${{ needs.prepare.outputs.has-prisma-changes == 'true' }}
+ uses: ./.github/workflows/check-prisma-migrations.yml
+ secrets: inherit
+
setup-db:
name: Setup Database
needs: [prepare]
@@ -356,7 +373,7 @@ jobs:
build-companion:
name: Companion builds
needs: [prepare]
- if: needs.prepare.outputs.has_companion == 'true'
+ if: needs.prepare.outputs.has-companion == 'true'
uses: ./.github/workflows/companion-build.yml
secrets: inherit
@@ -432,6 +449,7 @@ jobs:
unit-test,
api-v2-unit-test,
check-api-v2-breaking-changes,
+ check-prisma-migrations,
integration-test,
build,
build-api-v1,
@@ -471,6 +489,7 @@ jobs:
needs.unit-test.result != 'success' ||
needs.api-v2-unit-test.result != 'success' ||
(needs.prepare.outputs.has-api-v2-changes == 'true' && needs.check-api-v2-breaking-changes.result != 'success') ||
+ (needs.prepare.outputs.has-prisma-changes == 'true' && needs.check-prisma-migrations.result != 'success') ||
needs.build.result != 'success' ||
needs.build-api-v1.result != 'success' ||
needs.build-api-v2.result != 'success' ||
@@ -486,6 +505,6 @@ jobs:
)
) ||
(
- needs.prepare.outputs.has_companion == 'true' &&
+ needs.prepare.outputs.has-companion == 'true' &&
needs.build-companion.result != 'success'
)