-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (69 loc) · 2.64 KB
/
Copy pathmigrate-db.yml
File metadata and controls
82 lines (69 loc) · 2.64 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
# Migrate DB — deploy pending migrations to long-lived environments
#
# Required secrets (GitHub → Settings → Secrets and variables → Actions):
# PRODUCTION_DATABASE_URL — direct/unpooled Postgres connection string for the
# production database; used on pushes to `main`.
# DEV_DATABASE_URL — direct/unpooled Postgres connection string for the
# dev database; used on pushes to `dev`.
#
# Both secrets MUST use a direct (unpooled) connection — `prisma migrate deploy`
# requires a direct connection; a pooled/PgBouncer endpoint will cause the
# migration step to fail. The selected secret is assigned to DATABASE_URL at
# runtime by branch.
#
# Failure model: a failed migration fails this workflow loudly (no continue-on-error).
# There is no automated rollback — manual intervention is required on failure.
name: Migrate DB
on:
push:
branches: [main, dev]
paths:
- 'prisma/migrations/**'
concurrency:
group: migrate-db-${{ github.ref }}
cancel-in-progress: false # migrations must not be interrupted mid-apply
permissions:
contents: read
jobs:
migrate:
name: Deploy migrations
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: npm
- name: Install dependencies
run: npm ci
- name: Select database URL
env:
PRODUCTION_DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }}
DEV_DATABASE_URL: ${{ secrets.DEV_DATABASE_URL }}
run: |
case "${{ github.ref_name }}" in
main)
SELECTED_SECRET="$PRODUCTION_DATABASE_URL"
SECRET_NAME="PRODUCTION_DATABASE_URL"
;;
dev)
SELECTED_SECRET="$DEV_DATABASE_URL"
SECRET_NAME="DEV_DATABASE_URL"
;;
*)
echo "::error::Unrecognized branch '${{ github.ref_name }}'. Update on.push.branches and the case statement together."
exit 1
;;
esac
if [ -z "$SELECTED_SECRET" ]; then
echo "::error::Required secret $SECRET_NAME for branch ${{ github.ref_name }} is not configured. Add it under GitHub → Settings → Secrets and variables → Actions."
exit 1
fi
echo "DATABASE_URL=$SELECTED_SECRET" >> "$GITHUB_ENV"
- name: Generate Prisma client
run: npm run prisma:generate
- name: Apply migrations
run: npm run prisma:migrate:deploy