From e78f78e3f689389863612762180a0761e47178e2 Mon Sep 17 00:00:00 2001 From: varutasu <104105839+varutasu@users.noreply.github.com> Date: Tue, 2 Jun 2026 11:01:18 -0500 Subject: [PATCH] ci: run migrations against Postgres service container in CI (#64) * ci: run migrations against Postgres service container in CI Add a migrate job that applies node-pg-migrate against an ephemeral Postgres 16 service container so broken migrations fail at PR time. Co-authored-by: Cursor * fix(migrations): retimestamp scan tables after initial-schema. Fresh CI/postgres runs failed because 1748365200000 sorted before initial-schema. Renamed to 1779853647566 with IF NOT EXISTS guards intact. Co-authored-by: Cursor * fix(migrations): ensure is_system_collection exists before description backfill. Fresh CI Postgres runs initial-schema without this column (added historically via scripts); ADD COLUMN IF NOT EXISTS makes the data migration safe on new and existing envs. Co-authored-by: Cursor --------- Co-authored-by: Cursor --- .github/workflows/ci.yml | 31 +++++++++++++++++++ docs/SCHEMA_MAP.md | 2 +- ...es.js => 1779853647566_add-scan-tables.js} | 5 +++ ...378340194_system-collection-description.js | 3 ++ 4 files changed, 40 insertions(+), 1 deletion(-) rename migrations/{1748365200000_add-scan-tables.js => 1779853647566_add-scan-tables.js} (85%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28b5385..593aeee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ name: CI # What this CI covers (and Vercel does not): # - Lint (cheap belt-and-suspenders) # - Schema-map drift check (docs/SCHEMA_MAP.md updated when scripts/add-*.js changes) +# - Migrations apply cleanly (node-pg-migrate against ephemeral Postgres 16) # - Unit tests (vitest) # # NOTE: tcg-vault is JavaScript (not TypeScript). No `npx tsc --noEmit` step. @@ -230,6 +231,36 @@ jobs: fi echo "OK: no forbidden stale strings in pages/ or components/." + migrate: + name: Migrations apply (node-pg-migrate) + runs-on: ubuntu-latest + services: + postgres: + image: postgres:16 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: deckhearth_test + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_URL: postgres://postgres:postgres@localhost:5432/deckhearth_test + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: npm + - run: npm ci + - name: Write migrate env file + run: echo "POSTGRES_URL=${POSTGRES_URL}" >> .env.local + - run: npm run migrate up + test: name: Unit tests (vitest) runs-on: ubuntu-latest diff --git a/docs/SCHEMA_MAP.md b/docs/SCHEMA_MAP.md index 90f491a..9a46511 100644 --- a/docs/SCHEMA_MAP.md +++ b/docs/SCHEMA_MAP.md @@ -178,7 +178,7 @@ ### card_submissions -Added by `migrations/1748365200000_add-scan-tables.js` (server-side scan pipeline). Unknown high-confidence scans queue here for admin review instead of polluting `cards`. +Added by `migrations/1779853647566_add-scan-tables.js` (server-side scan pipeline). Unknown high-confidence scans queue here for admin review instead of polluting `cards`. | Column | Type | Notes | | --- | --- | --- | diff --git a/migrations/1748365200000_add-scan-tables.js b/migrations/1779853647566_add-scan-tables.js similarity index 85% rename from migrations/1748365200000_add-scan-tables.js rename to migrations/1779853647566_add-scan-tables.js index 310ff72..2cddb01 100644 --- a/migrations/1748365200000_add-scan-tables.js +++ b/migrations/1779853647566_add-scan-tables.js @@ -1,6 +1,11 @@ /** * card_submissions + scan_attempts for server-side scan pipeline. * + * Retimestamped from 1748365200000 → 1779853647566 so fresh DBs run + * initial-schema before scan tables (FK to users). Existing envs that + * already recorded the old name in pgmigrations are unaffected; IF NOT EXISTS + * guards make re-application safe if the new name is pending. + * * @type {import('node-pg-migrate').ColumnDefinitions | undefined} */ export const shorthands = undefined; diff --git a/migrations/1780378340194_system-collection-description.js b/migrations/1780378340194_system-collection-description.js index 89b2abb..2998024 100644 --- a/migrations/1780378340194_system-collection-description.js +++ b/migrations/1780378340194_system-collection-description.js @@ -13,6 +13,9 @@ export const shorthands = undefined; */ export const up = (pgm) => { pgm.sql(` + ALTER TABLE collections + ADD COLUMN IF NOT EXISTS is_system_collection BOOLEAN DEFAULT false; + UPDATE collections SET description = 'Automatically syncs with My Collection. This list cannot be deleted or made public.' WHERE is_system_collection = true