Skip to content

Commit 11d285d

Browse files
improvement(ci): resolve migration db url from prefixed repo secrets, drop github environments
1 parent 4eeb81b commit 11d285d

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
(github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging')
5858
uses: ./.github/workflows/migrations.yml
5959
with:
60-
environment: ${{ github.ref == 'refs/heads/main' && 'db-production' || 'db-staging' }}
60+
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
6161
secrets: inherit
6262

6363
# Same ordering for dev (schema push before the dev image lands in ECR)
@@ -66,7 +66,7 @@ jobs:
6666
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
6767
uses: ./.github/workflows/migrations.yml
6868
with:
69-
environment: db-dev
69+
environment: dev
7070
secrets: inherit
7171

7272
# Dev: build all 3 images for ECR only (no GHCR, no ARM64)

.github/workflows/migrations.yml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ on:
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

2121
permissions:
2222
contents: read
@@ -25,7 +25,6 @@ jobs:
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

Comments
 (0)