-
Notifications
You must be signed in to change notification settings - Fork 3
77 lines (73 loc) · 2.71 KB
/
Copy pathdb-migrate.yml
File metadata and controls
77 lines (73 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: DB Migrate
on:
pull_request:
paths:
- infra/supabase/migrations/**
- packages/db/src/schema/**
- packages/db/drizzle/**
- scripts/migrate.ts
- .github/workflows/db-migrate.yml
workflow_dispatch:
concurrency:
group: db-migrate
cancel-in-progress: false
jobs:
diff:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
env:
# Empty unless the SUPABASE_MIGRATION_URL secret is configured. Gates the
# connection-dependent migration-plan step below.
MIGRATION_DB_URL: ${{ secrets.SUPABASE_MIGRATION_URL }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 10.33.2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
# drizzle.config.ts imports @cheatcode/env/migrate (built ./dist), so build the db
# package's workspace dep closure before generate — otherwise db:generate fails with
# "Cannot find module @cheatcode/env/dist/migrate.js" on a fresh runner.
- run: pnpm turbo build --filter=@cheatcode/db^...
# drizzle-kit generate reads the schema and never connects; a placeholder URL just
# satisfies drizzle.config.ts's eager loadMigrationEnv() call.
- run: pnpm --filter @cheatcode/db db:generate
env:
SUPABASE_MIGRATION_URL: postgres://placeholder@localhost:5432/placeholder
- name: Fail if Drizzle migrations drifted
run: git diff --exit-code packages/db/drizzle
# The pending-plan comment needs a real DB connection, so it only runs when the
# SUPABASE_MIGRATION_URL secret is configured (it is not today). The drift check
# above is the gate; this stays best-effort.
- name: Compute pending migration plan
if: env.MIGRATION_DB_URL != ''
run: pnpm tsx scripts/migrate.ts --dry-run | tee migration-plan.txt
env:
SUPABASE_MIGRATION_URL: ${{ env.MIGRATION_DB_URL }}
- uses: marocchino/sticky-pull-request-comment@v2
if: env.MIGRATION_DB_URL != ''
with:
header: db-migration-plan
path: migration-plan.txt
apply:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 10.33.2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Apply migrations
run: pnpm tsx scripts/migrate.ts --apply
env:
SUPABASE_MIGRATION_URL: ${{ secrets.SUPABASE_MIGRATION_URL }}