77 - packages/db/src/schema/**
88 - packages/db/drizzle/**
99 - scripts/migrate.ts
10+ - .github/workflows/db-migrate.yml
1011 workflow_dispatch :
1112
1213concurrency :
1718 diff :
1819 if : github.event_name == 'pull_request'
1920 runs-on : ubuntu-latest
21+ env :
22+ # Empty unless the SUPABASE_MIGRATION_URL secret is configured. Gates the
23+ # connection-dependent migration-plan step below.
24+ MIGRATION_DB_URL : ${{ secrets.SUPABASE_MIGRATION_URL }}
2025 steps :
2126 - uses : actions/checkout@v4
2227 - uses : pnpm/action-setup@v4
@@ -27,14 +32,27 @@ jobs:
2732 node-version : 22
2833 cache : pnpm
2934 - run : pnpm install --frozen-lockfile
35+ # drizzle.config.ts imports @cheatcode/env/migrate (built ./dist), so build the db
36+ # package's workspace dep closure before generate — otherwise db:generate fails with
37+ # "Cannot find module @cheatcode/env/dist/migrate.js" on a fresh runner.
38+ - run : pnpm turbo build --filter=@cheatcode/db^...
39+ # drizzle-kit generate reads the schema and never connects; a placeholder URL just
40+ # satisfies drizzle.config.ts's eager loadMigrationEnv() call.
3041 - run : pnpm --filter @cheatcode/db db:generate
42+ env :
43+ SUPABASE_MIGRATION_URL : postgres://placeholder@localhost:5432/placeholder
3144 - name : Fail if Drizzle migrations drifted
3245 run : git diff --exit-code packages/db/drizzle
46+ # The pending-plan comment needs a real DB connection, so it only runs when the
47+ # SUPABASE_MIGRATION_URL secret is configured (it is not today). The drift check
48+ # above is the gate; this stays best-effort.
3349 - name : Compute pending migration plan
50+ if : env.MIGRATION_DB_URL != ''
3451 run : pnpm tsx scripts/migrate.ts --dry-run | tee migration-plan.txt
3552 env :
36- SUPABASE_MIGRATION_URL : ${{ secrets.SUPABASE_MIGRATION_URL }}
53+ SUPABASE_MIGRATION_URL : ${{ env.MIGRATION_DB_URL }}
3754 - uses : marocchino/sticky-pull-request-comment@v2
55+ if : env.MIGRATION_DB_URL != ''
3856 with :
3957 header : db-migration-plan
4058 path : migration-plan.txt
0 commit comments