Skip to content

Merge pull request #137 from peelar/misc #34

Merge pull request #137 from peelar/misc

Merge pull request #137 from peelar/misc #34

Workflow file for this run

name: Production Database Migration
on:
push:
branches: [main]
workflow_dispatch:
inputs:
skip_vercel_deploy:
description: 'Skip Vercel deploy after migration'
required: false
default: 'false'
type: boolean
jobs:
migrate:
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'
- name: Get pnpm version
id: pnpm-version
run: |
PNPM_VERSION=$(node -p "require('./package.json').packageManager?.replace('pnpm@', '') || '9'")
echo "version=$PNPM_VERSION" >> $GITHUB_OUTPUT
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ steps.pnpm-version.outputs.version }}
- name: Cache pnpm store
uses: actions/cache@v4
with:
path: ~/.local/share/pnpm/store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-
- name: Install dependencies
run: pnpm install --frozen-lockfile
# Dry-run: Check pending migrations
- name: Check pending migrations
id: check
working-directory: apps/app
env:
DATABASE_URL: ${{ secrets.DIRECT_DATABASE_URL }}
run: |
echo "=== Migration Status ==="
OUTPUT=$(npx prisma migrate status 2>&1) || true
echo "$OUTPUT"
if echo "$OUTPUT" | grep -q "Database schema is up to date"; then
echo "has_pending=false" >> $GITHUB_OUTPUT
echo "::notice::Database is up to date - no migrations needed"
else
echo "has_pending=true" >> $GITHUB_OUTPUT
echo "::warning::Pending migrations detected"
fi
# Validate schema before applying
- name: Validate schema
if: steps.check.outputs.has_pending == 'true'
working-directory: apps/app
run: |
echo "=== Validating Schema ==="
npx prisma validate
echo "::notice::Schema validation passed"
# Apply migrations
- name: Apply migrations
if: steps.check.outputs.has_pending == 'true'
working-directory: apps/app
env:
DATABASE_URL: ${{ secrets.DIRECT_DATABASE_URL }}
run: |
echo "=== Applying Migrations ==="
npx prisma migrate deploy
echo "::notice::Migrations applied successfully"
deploy:
needs: migrate
runs-on: ubuntu-latest
# Run after migrate completes (success or skipped), unless explicitly skipped
if: >-
${{ !failure() && !cancelled() &&
(github.event_name != 'workflow_dispatch' || github.event.inputs.skip_vercel_deploy != 'true') }}
steps:
- name: Trigger Vercel deploy
env:
VERCEL_DEPLOY_HOOK: ${{ secrets.VERCEL_DEPLOY_HOOK }}
run: |
if [ -z "$VERCEL_DEPLOY_HOOK" ]; then
echo "::error::VERCEL_DEPLOY_HOOK secret is not set"
exit 1
fi
echo "=== Triggering Vercel Deploy ==="
curl -X POST "$VERCEL_DEPLOY_HOOK"
echo "::notice::Vercel deploy triggered"