44 workflow_call :
55 inputs :
66 environment :
7- description : Target GitHub environment (db- production, db- staging, or db- dev)
7+ description : Target environment (production, staging, or dev)
88 required : true
99 type : string
1010 workflow_dispatch :
1111 inputs :
1212 environment :
13- description : Target GitHub environment
13+ description : Target environment
1414 required : true
1515 type : choice
1616 options :
17- - db- production
18- - db- staging
19- - db- dev
17+ - production
18+ - staging
19+ - dev
2020
2121permissions :
2222 contents : read
2525 migrate :
2626 name : Apply Database Migrations
2727 runs-on : blacksmith-4vcpu-ubuntu-2404
28- environment : ${{ inputs.environment }}
2928
3029 steps :
3130 - name : Checkout code
@@ -50,24 +49,23 @@ jobs:
5049 - name : Install dependencies
5150 run : bun install --frozen-lockfile
5251
53- # MIGRATIONS_DATABASE_URL is an environment-scoped secret with no repo-level
54- # fallback: if it's missing on the target environment it resolves to empty and
55- # the guard below fails the job, instead of silently inheriting another
56- # environment's database
52+ # The expression maps the explicit environment input to exactly one repo
53+ # secret, so the job never holds another environment's database URL. An
54+ # unknown environment resolves to empty and the guard below fails the job.
5755 - name : Apply database schema changes
5856 working-directory : ./packages/db
5957 env :
60- DATABASE_URL : ${{ secrets.MIGRATIONS_DATABASE_URL }}
58+ DATABASE_URL : ${{ inputs.environment == 'production' && secrets.DATABASE_URL || inputs.environment == 'staging' && secrets.STAGING_DATABASE_URL || inputs.environment == 'dev' && secrets.DEV_DATABASE_URL || '' }}
6159 ENVIRONMENT : ${{ inputs.environment }}
6260 run : |
6361 if [ -z "$DATABASE_URL" ]; then
64- echo "ERROR: MIGRATIONS_DATABASE_URL is not set on environment '${ENVIRONMENT}'" >&2
62+ echo "ERROR: no database URL secret resolved for environment '${ENVIRONMENT}'" >&2
6563 exit 1
6664 fi
6765
6866 echo "Applying versioned migrations (db:migrate)"
6967 bun run ./scripts/migrate.ts
70- if [ "${ENVIRONMENT}" = "db- dev" ]; then
68+ if [ "${ENVIRONMENT}" = "dev" ]; then
7169 echo "Dev environment — also pushing unversioned schema drift (db:push)"
7270 bun run db:push --force
7371 fi
0 commit comments