Merge pull request #737 from olywales-stack/fix/674-analytics-cache-m… #322
This file contains hidden or 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: Backend CI | |
| on: | |
| pull_request: | |
| paths: | |
| - "backend/**" | |
| - ".github/workflows/backend.yml" | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "backend/**" | |
| - ".github/workflows/backend.yml" | |
| jobs: | |
| backend: | |
| name: Backend checks | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: backend | |
| services: | |
| postgres: | |
| image: postgres:16 | |
| env: | |
| POSTGRES_DB: novasupport_test | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd "pg_isready -U postgres -d novasupport_test" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| env: | |
| DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:5432/novasupport_test | |
| DIRECT_URL: postgresql://postgres:postgres@127.0.0.1:5432/novasupport_test | |
| NODE_ENV: test | |
| SKIP_HORIZON_VALIDATION: "true" | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha || github.sha }} | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.x | |
| cache: npm | |
| cache-dependency-path: backend/package-lock.json | |
| - name: Install backend dependencies | |
| run: npm ci | |
| - name: Generate Prisma client | |
| run: npm run db:generate | |
| - name: Validate Prisma schema | |
| run: npx prisma validate | |
| - name: Apply database migrations | |
| run: npm run db:migrate:deploy | |
| - name: Validate database migrations | |
| run: | | |
| set +e | |
| DRIFT=$(npx prisma migrate diff \ | |
| --from-schema-datamodel prisma/schema.prisma \ | |
| --to-migrations prisma/migrations \ | |
| --shadow-database-url "$DATABASE_URL" \ | |
| --exit-code 2>&1) | |
| DRIFT_EXIT=$? | |
| set -e | |
| echo "::group::Schema drift diff output" | |
| echo "$DRIFT" | |
| echo "::endgroup::" | |
| if [ $DRIFT_EXIT -ne 0 ]; then | |
| echo "" | |
| echo "============================================" | |
| echo " ❌ MIGRATION VALIDATION FAILED" | |
| echo "============================================" | |
| echo "" | |
| echo " Drift detected — see diff output above." | |
| echo "" | |
| echo " To fix: create a new migration:" | |
| echo " cd backend" | |
| echo " npx prisma migrate dev --name describe_your_changes" | |
| echo "" | |
| exit 1 | |
| fi | |
| echo "✅ Schema and migrations are in sync." | |
| env: | |
| DATABASE_URL: ${{ env.DATABASE_URL }} | |
| - name: Run backend tests | |
| run: npm run test | |
| - name: Build backend | |
| run: npm run build |