-
Notifications
You must be signed in to change notification settings - Fork 514
Expand file tree
/
Copy pathdb-migration-backwards-compatibility.yaml
More file actions
432 lines (349 loc) · 15.1 KB
/
db-migration-backwards-compatibility.yaml
File metadata and controls
432 lines (349 loc) · 15.1 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
name: DB migration compat
on:
push:
branches-ignore:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/dev' }}
jobs:
check-migrations-changed:
name: Check if migrations changed
runs-on: ubuntu-latest
outputs:
migrations_changed: ${{ steps.check-diff.outputs.migrations_changed }}
base_branch: ${{ steps.check-diff.outputs.base_branch }}
steps:
- name: Checkout current branch
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for migration changes
id: check-diff
run: |
# Determine base branch: dev compares to main, all others compare to dev
if [ "${{ github.ref }}" = "refs/heads/dev" ]; then
BASE_BRANCH="main"
else
BASE_BRANCH="dev"
fi
echo "base_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT
# Get the merge base with the base branch
git fetch origin $BASE_BRANCH
MERGE_BASE=$(git merge-base HEAD origin/$BASE_BRANCH)
# Check if there are any changes in the migrations folder
if git diff --quiet "$MERGE_BASE" HEAD -- apps/backend/prisma/migrations/; then
echo "No changes in migrations folder"
echo "migrations_changed=false" >> $GITHUB_OUTPUT
else
echo "Migrations have changed"
echo "migrations_changed=true" >> $GITHUB_OUTPUT
fi
backwards-compatibility:
name: Back-compat — Current branch migrations with ${{ needs.check-migrations-changed.outputs.base_branch }} branch code
needs: check-migrations-changed
if: needs.check-migrations-changed.outputs.migrations_changed == 'true'
runs-on: ubicloud-standard-8
env:
NODE_ENV: test
STACK_ENABLE_HARDCODED_PASSKEY_CHALLENGE_FOR_TESTING: yes
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe"
steps:
# First, checkout the current branch to get its migrations
- name: Checkout current branch
uses: actions/checkout@v6
with:
path: current-branch
# Save the migrations folder from the current branch
- name: Save current branch migrations
run: |
mkdir -p saved-migrations
cp -r current-branch/apps/backend/prisma/migrations/* saved-migrations/
# Now checkout base branch (main for dev, dev for all others)
- name: Checkout base branch
uses: actions/checkout@v6
with:
ref: ${{ needs.check-migrations-changed.outputs.base_branch }}
path: base-branch
# Move base-branch to the root for the rest of the workflow (keep base's migrations for now)
- name: Setup working directory
run: |
shopt -s dotglob
mv base-branch/* .
rm -rf base-branch current-branch
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22.x
- name: Setup pnpm
uses: pnpm/action-setup@v4
# Start Docker Compose in the background
- name: Start Docker Compose in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: docker compose -f docker/dependencies/docker.compose.yaml up --pull always -d &
wait-on: /dev/null
tail: true
wait-for: 3s
log-output-if: true
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Create .env.test.local file for apps/backend
run: cp apps/backend/.env.development apps/backend/.env.test.local
- name: Create .env.test.local file for apps/dashboard
run: cp apps/dashboard/.env.development apps/dashboard/.env.test.local
- name: Create .env.test.local file for apps/e2e
run: cp apps/e2e/.env.development apps/e2e/.env.test.local
- name: Create .env.test.local file for docs
run: cp docs/.env.development docs/.env.test.local
- name: Create .env.test.local file for examples/cjs-test
run: cp examples/cjs-test/.env.development examples/cjs-test/.env.test.local
- name: Create .env.test.local file for examples/demo
run: cp examples/demo/.env.development examples/demo/.env.test.local
- name: Create .env.test.local file for examples/docs-examples
run: cp examples/docs-examples/.env.development examples/docs-examples/.env.test.local
- name: Create .env.test.local file for examples/e-commerce
run: cp examples/e-commerce/.env.development examples/e-commerce/.env.test.local
- name: Create .env.test.local file for examples/middleware
run: cp examples/middleware/.env.development examples/middleware/.env.test.local
- name: Create .env.test.local file for examples/supabase
run: cp examples/supabase/.env.development examples/supabase/.env.test.local
- name: Create .env.test.local file for examples/convex
run: cp examples/convex/.env.development examples/convex/.env.test.local
- name: Create .env.test.local file for apps/internal-tool
run: cp apps/internal-tool/.env.development apps/internal-tool/.env.test.local
- name: Build
run: pnpm build
- name: Wait on Postgres
run: pnpm run wait-until-postgres-is-ready:pg_isready
- name: Wait on Inbucket
run: pnpm exec wait-on tcp:localhost:8129
- name: Wait on Svix
run: pnpm exec wait-on tcp:localhost:8113
- name: Wait on ClickHouse
run: pnpm exec wait-on http://localhost:8136/ping
- name: Initialize database
run: pnpm run db:init
- name: Start stack-backend in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: pnpm run start:backend --log-order=stream &
wait-on: |
http://localhost:8102
tail: true
wait-for: 30s
log-output-if: true
- name: Start stack-dashboard in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: pnpm run start:dashboard --log-order=stream &
wait-on: |
http://localhost:8101
tail: true
wait-for: 30s
log-output-if: true
- name: Start mock-oauth-server in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: pnpm run start:mock-oauth-server --log-order=stream &
wait-on: |
http://localhost:8102
tail: true
wait-for: 30s
log-output-if: true
- name: Start run-email-queue in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: pnpm -C apps/backend run run-email-queue --log-order=stream &
wait-on: |
http://localhost:8102
tail: true
wait-for: 30s
log-output-if: true
- name: Start run-cron-jobs in background
uses: JarvusInnovations/background-action@v1.0.7
if: ${{ hashFiles('apps/backend/scripts/run-cron-jobs.ts') != '' }}
with:
run: pnpm -C apps/backend run run-cron-jobs:test --log-order=stream &
wait-on: |
http://localhost:8102
tail: true
wait-for: 30s
log-output-if: true
- name: Wait 10 seconds
run: sleep 10
# First test run: base branch with base's migrations
- name: Run tests (base branch with original migrations)
run: pnpm test
# Now copy over current branch's migrations and run migrate
- name: Replace migrations with current branch migrations
run: |
rm -rf apps/backend/prisma/migrations/*
cp -r saved-migrations/* apps/backend/prisma/migrations/
rm -rf saved-migrations
- name: Run database migrations
run: pnpm run db:migrate
# Second test run: base branch code with new migrations applied
- name: Run tests (base branch with new migrations)
run: pnpm test
- name: Verify data integrity
run: pnpm run verify-data-integrity --no-bail
- name: Print Docker Compose logs
if: always()
run: docker compose -f docker/dependencies/docker.compose.yaml logs
forward-compatibility:
name: Forward-compat — Current branch code with ${{ needs.check-migrations-changed.outputs.base_branch }} branch migrations
needs: [check-migrations-changed, backwards-compatibility]
if: always() && needs.backwards-compatibility.result == 'failure'
runs-on: ubicloud-standard-8
env:
NODE_ENV: test
STACK_ENABLE_HARDCODED_PASSKEY_CHALLENGE_FOR_TESTING: yes
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe"
steps:
# First, checkout the base branch to get its migrations
- name: Checkout base branch
uses: actions/checkout@v6
with:
ref: ${{ needs.check-migrations-changed.outputs.base_branch }}
path: base-branch
- name: Save base branch migrations
run: |
mkdir -p saved-migrations
cp -r base-branch/apps/backend/prisma/migrations/* saved-migrations/
# Now checkout current branch (new code)
- name: Checkout current branch
uses: actions/checkout@v6
with:
path: current-branch
# Move current branch to the root for the rest of the workflow
- name: Setup working directory
run: |
shopt -s dotglob
mv current-branch/* .
rm -rf current-branch base-branch
# Replace current branch's migrations with base branch's (old) migrations
- name: Replace migrations with base branch migrations
run: |
rm -rf apps/backend/prisma/migrations/*
cp -r saved-migrations/* apps/backend/prisma/migrations/
rm -rf saved-migrations
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22.x
- name: Setup pnpm
uses: pnpm/action-setup@v4
# Start Docker Compose in the background
- name: Start Docker Compose in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: docker compose -f docker/dependencies/docker.compose.yaml up --pull always -d &
wait-on: /dev/null
tail: true
wait-for: 3s
log-output-if: true
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Create .env.test.local file for apps/backend
run: cp apps/backend/.env.development apps/backend/.env.test.local
- name: Create .env.test.local file for apps/dashboard
run: cp apps/dashboard/.env.development apps/dashboard/.env.test.local
- name: Create .env.test.local file for apps/e2e
run: cp apps/e2e/.env.development apps/e2e/.env.test.local
- name: Create .env.test.local file for docs
run: cp docs/.env.development docs/.env.test.local
- name: Create .env.test.local file for examples/cjs-test
run: cp examples/cjs-test/.env.development examples/cjs-test/.env.test.local
- name: Create .env.test.local file for examples/demo
run: cp examples/demo/.env.development examples/demo/.env.test.local
- name: Create .env.test.local file for examples/docs-examples
run: cp examples/docs-examples/.env.development examples/docs-examples/.env.test.local
- name: Create .env.test.local file for examples/e-commerce
run: cp examples/e-commerce/.env.development examples/e-commerce/.env.test.local
- name: Create .env.test.local file for examples/middleware
run: cp examples/middleware/.env.development examples/middleware/.env.test.local
- name: Create .env.test.local file for examples/supabase
run: cp examples/supabase/.env.development examples/supabase/.env.test.local
- name: Create .env.test.local file for examples/convex
run: cp examples/convex/.env.development examples/convex/.env.test.local
- name: Create .env.test.local file for apps/internal-tool
run: cp apps/internal-tool/.env.development apps/internal-tool/.env.test.local
- name: Build
run: pnpm build
- name: Wait on Postgres
run: pnpm run wait-until-postgres-is-ready:pg_isready
- name: Wait on Inbucket
run: pnpm exec wait-on tcp:localhost:8129
- name: Wait on Svix
run: pnpm exec wait-on tcp:localhost:8113
- name: Wait on ClickHouse
run: pnpm exec wait-on http://localhost:8136/ping
- name: Initialize database
run: pnpm run db:init
- name: Start stack-backend in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: pnpm run start:backend --log-order=stream &
wait-on: |
http://localhost:8102
tail: true
wait-for: 30s
log-output-if: true
- name: Start stack-dashboard in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: pnpm run start:dashboard --log-order=stream &
wait-on: |
http://localhost:8101
tail: true
wait-for: 30s
log-output-if: true
- name: Start mock-oauth-server in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: pnpm run start:mock-oauth-server --log-order=stream &
wait-on: |
http://localhost:8102
tail: true
wait-for: 30s
log-output-if: true
- name: Start run-email-queue in background
uses: JarvusInnovations/background-action@v1.0.7
with:
run: pnpm -C apps/backend run run-email-queue --log-order=stream &
wait-on: |
http://localhost:8102
tail: true
wait-for: 30s
log-output-if: true
- name: Start run-cron-jobs in background
uses: JarvusInnovations/background-action@v1.0.7
if: ${{ hashFiles('apps/backend/scripts/run-cron-jobs.ts') != '' }}
with:
run: pnpm -C apps/backend run run-cron-jobs:test --log-order=stream &
wait-on: |
http://localhost:8102
tail: true
wait-for: 30s
log-output-if: true
- name: Wait 10 seconds
run: sleep 10
# Run tests: current branch code with base branch (old) migrations
- name: Run tests (current branch code with base branch migrations)
run: pnpm test
- name: Verify data integrity
run: pnpm run verify-data-integrity --no-bail
- name: Print Docker Compose logs
if: always()
run: docker compose -f docker/dependencies/docker.compose.yaml logs
# This job runs when migrations haven't changed, ensuring the workflow succeeds
skip-unchanged:
name: No migration changes (skipped)
needs: check-migrations-changed
if: needs.check-migrations-changed.outputs.migrations_changed == 'false'
runs-on: ubuntu-latest
steps:
- name: No migration changes detected
run: echo "No changes to migrations folder detected. Skipping backwards compatibility test."