Feat/home #9
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: Check Prisma Migrations | |
on: | |
pull_request: | |
paths: | |
- 'apps/server/prisma/schema.prisma' | |
types: [opened, synchronize, reopened] | |
jobs: | |
check-migrations: | |
runs-on: ubuntu-latest | |
environment: development | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.10.0 | |
cache: yarn | |
- name: Install dependencies | |
run: | | |
yarn install | |
- name: Check for Prisma schema and migration consistency | |
run: | | |
echo "Checking changes between commits..." | |
# Ensure the base branch is fetched | |
git fetch origin ${{ github.base_ref }} | |
# Get the changed files between the base branch and the PR head | |
changed_files=$(git diff --name-only origin/${{ github.base_ref }} HEAD) | |
echo "Changed files: $changed_files" | |
# Check if schema.prisma has been modified | |
if echo "$changed_files" | grep -q 'apps/server/prisma/schema.prisma'; then | |
echo "🔍 Schema.prisma has been modified. Checking migrations..." | |
cd apps/server | |
# Run Prisma migrate diff to verify the migration consistency | |
npx prisma migrate diff \ | |
--from-schema-datamodel prisma/schema.prisma \ | |
--to-migrations prisma/migrations \ | |
--shadow-database-url ${{ secrets.SHADOW_DB_URL }} \ | |
--script > migration_diff.sql | |
# Check if there are any differences | |
if [ "$(cat migration_diff.sql | grep -v '^$' | tr -d '\n')" = "-- This is an empty migration." ]; then | |
echo "✅ Schema and migrations are consistent." | |
else | |
echo "❌ Detected differences between schema.prisma and migration files!" | |
echo "------------------------------------------" | |
echo "Generated migration diff:" | |
cat migration_diff.sql | |
echo "------------------------------------------" | |
echo "Please ensure all schema changes are reflected in migration files." | |
echo "You can use the following command to generate migrations:" | |
echo "" | |
echo " npx prisma migrate dev" | |
echo "" | |
echo "Once done, commit the migration files and push your changes." | |
echo "------------------------------------------" | |
exit 1 | |
fi | |
else | |
echo "✅ No changes to schema.prisma detected. All good!" | |
fi |