TL-M0-18 · CI database job
Why: Until now, CI never touched the database. This step adds a database job to CI. On every pull request that changes the database side, it starts the real local Supabase stack, resets it, runs every pgTAP test, regenerates the types and the reference pages, and fails if any generated file differs from what is committed (D12, D19, D27, D33). A path filter decides when it runs, not Turborepo's affected graph, because supabase/ is not a package (D12). After the job has run green once, the ruleset makes it required, so a pull request that breaks a test or forgets to regenerate the types can't merge.
ID TL-M0-18 · Level L0 · Run order row 23 · Issue #15
CI has three jobs: checks, changes and database. The database job runs on pull requests that touch the database side and on every push to main, and it passes. A pull request that touches nothing on the database side shows database as skipped. The ruleset on main requires checks, pr-title and database. Since #732, the push to main skips the database and e2e jobs: the pull request into main has already run them.
Before
Section titled “Before”- Row 22, BE pack E (#14), is Done: pnpm db:types and pnpm docs:reference exist, and the committed types and reference pages come from the current schema.
- You are on main in ~/opleet-v2/opleet, up to date, and
git status --shortprints nothing. - Docker Desktop is running.
1 · Check that main is clean the way CI will check it
Section titled “1 · Check that main is clean the way CI will check it”This runs the database job's commands on your Mac first. If main's committed files are already stale, CI fails on its first run, and this block shows why before you push anything.
git switch main && git pullpnpm supabase startpnpm supabase db resetpnpm supabase test dbpnpm db:typespnpm docs:referencegit status --short -- packages/db-types apps/docs/src/content/docs/reference2 · A branch with the database job
Section titled “2 · A branch with the database job”This replaces .github/workflows/ci.yml as a whole. The checks job is unchanged; changes and database are new.
git switch -c ci/databasecat > .github/workflows/ci.yml <<'EOF'name: CI
on: pull_request: push: branches: [main]
concurrency: group: ci-${{ github.ref }} cancel-in-progress: true
env: NEXT_TELEMETRY_DISABLED: 1 ASTRO_TELEMETRY_DISABLED: 1 TURBO_TELEMETRY_DISABLED: 1
jobs: checks: name: checks runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 with: fetch-depth: 0 - uses: pnpm/action-setup@v6 - uses: actions/setup-node@v7 with: node-version-file: .node-version cache: pnpm - run: pnpm install --frozen-lockfile - run: pnpm biome ci . - run: pnpm docs:rules - run: pnpm turbo run typecheck build ${{ github.event_name == 'pull_request' && '--affected' || '' }}
# Decides whether the database job runs: a path filter, not Turborepo's affected graph, # because supabase/ is not a package (D12). The filter lives in a job rather than in # on.paths, so the database check always reports: skipped counts as passing in the ruleset. changes: name: changes runs-on: ubuntu-latest outputs: database: ${{ steps.filter.outputs.database }} steps: - uses: actions/checkout@v7 with: fetch-depth: 0 - id: filter name: Did this change touch the database side? env: EVENT: ${{ github.event_name }} BASE: ${{ github.event.pull_request.base.sha }} HEAD: ${{ github.event.pull_request.head.sha }} run: | if [ "$EVENT" != "pull_request" ]; then echo "database=true" >> "$GITHUB_OUTPUT" exit 0 fi paths='^(supabase/|tools/db/|packages/db-types/|apps/docs/src/content/docs/reference/|\.github/workflows/ci\.yml$|package\.json$|pnpm-lock\.yaml$)' if git diff --name-only "$BASE...$HEAD" | grep -Eq "$paths"; then echo "database=true" >> "$GITHUB_OUTPUT" else echo "database=false" >> "$GITHUB_OUTPUT" fi
database: name: database needs: changes if: needs.changes.outputs.database == 'true' runs-on: ubuntu-latest timeout-minutes: 25 steps: - uses: actions/checkout@v7 - uses: pnpm/action-setup@v6 - uses: actions/setup-node@v7 with: node-version-file: .node-version cache: pnpm - run: pnpm install --frozen-lockfile - name: A signing key for this run only (D13) run: pnpm db:signing-key - name: Start the local stack (D12) run: pnpm supabase start -x studio,imgproxy,mailpit,edge-runtime,logflare,vector,supavisor,realtime - run: pnpm supabase db reset - name: pgTAP (D19) run: pnpm supabase test db - name: Regenerate the types and the reference pages run: | pnpm db:types pnpm docs:reference - name: The generated files match the schema (D12, D27, D33) run: | generated="packages/db-types apps/docs/src/content/docs/reference" if [ -n "$(git status --porcelain -- $generated)" ]; then git status --short -- $generated git --no-pager diff --stat -- $generated echo "::error::Generated files are out of date. Run pnpm db:types and pnpm docs:reference with the stack up, and commit what they change (D33)." exit 1 fi echo "Types and reference pages are current." - if: always() run: pnpm supabase stop --no-backupEOFgit add .github/workflows/ci.ymlgit commit -m "ci: run the database job on database changes"3 · Push, open the pull request, and watch the checks
Section titled “3 · Push, open the pull request, and watch the checks”The pull request changes ci.yml, which is on the path filter, so the database job runs. The first run pulls the Supabase images, which takes a few minutes.
git push -u origin ci/databasegh pr create --fillgh pr checks --watch4 · See the job catch hand-edited types, then undo it
Section titled “4 · See the job catch hand-edited types, then undo it”echo "// edited by hand" >> packages/db-types/src/database.tsgit commit -am "test: a hand edit the database job must catch"git pushsleep 15 && gh pr checks --watchgit revert --no-edit HEADgit pushsleep 15 && gh pr checks --watch5 · Squash-merge and update main
Section titled “5 · Squash-merge and update main”gh pr merge --squash --delete-branchgit switch maingit pull6 · Make the database job required on main
Section titled “6 · Make the database job required on main”The job must have run once before the ruleset can require it. A pull request that skips the job still passes, because GitHub counts a skipped job as passing.
id=$(gh api repos/Opleettop/monorepo/rulesets --jq '.[] | select(.name == "main") | .id')gh api repos/Opleettop/monorepo/rulesets/$id \ --jq '{rules: [.rules[] | if .type == "required_status_checks" then .parameters.required_status_checks += [{"context": "database"}] else . end]}' \ | gh api -X PUT repos/Opleettop/monorepo/rulesets/$id --input - \ --jq '.rules[] | select(.type == "required_status_checks") | .parameters.required_status_checks | map(.context)'Expect
Section titled “Expect”- Block 1: pnpm supabase test db ends with "Result: PASS". The last command prints nothing. Any line it prints is a generated file that is already stale on main: stop, and see If it fails.
- Block 2: Lefthook shows ✔️ biome and ✔️ commitlint, then one file changed.
- Block 3: checks, changes, database and pr-title all pass. The database log ends with "Types and reference pages are current."
- Block 4:
- After the first push, database fails, with "Generated files are out of date" and packages/db-types/src/database.ts listed.
- After the revert, it passes again.
- checks passes both times: Biome skips database.ts, and a comment line typechecks.
- Block 5: "✓ Squashed and merged pull request".
- Block 6:
["checks", "pr-title", "database"].
gh run list --workflow CI --branch main --limit 1gh api repos/Opleettop/monorepo/rules/branches/main \ --jq '.[] | select(.type == "required_status_checks") | .parameters.required_status_checks | map(.context)'The run on main after the merge shows completed and success, and the required checks are checks, pr-title and database.
On the next pull request that touches only apps/web or apps/docs pages outside reference/, the database job shows as skipped, and the pull request can still merge. Note this in the run log when it happens.
If it fails
Section titled “If it fails”- Block 1 prints a file: main's generated files are stale. Don't start this step. Paste the output in #15. The Backend Engineer commits the regenerated files in a pull request first (D33).
- The database job fails in "Start the local stack": paste the step's log (
gh run view --log-failed). A pull limit or a registry error usually clears on a re-run:gh run rerun --failed. - The database job fails in "pgTAP": the tests fail on the CI stack but passed in block 1. Paste the log in #15. Don't merge.
- "Generated files are out of date" on block 3's run: the files differ between your Mac and CI, which can mean a different CLI version. Compare
pnpm supabase --versionwith the 2.119.0 pinned in package.json, and paste the step's log. - Block 6 errors: paste the output. The ruleset is unchanged until the PUT succeeds.
- Before merging: gh pr close --delete-branch.
- After merging: revert the commit with a new pull request.
- To undo block 6: run it again with
-=in place of+=. That removes database from the required checks, and do it before reverting the workflow, or every pull request waits for a check that never comes.
Log each run as a comment on #15: the date, what you ran, and the output that mattered.