Skip to content

feat(skills): user_skills table + /v1/skills CRUD (custom skills back… #7

feat(skills): user_skills table + /v1/skills CRUD (custom skills back…

feat(skills): user_skills table + /v1/skills CRUD (custom skills back… #7

Workflow file for this run

name: DB Migrate
on:
pull_request:
paths:
- infra/supabase/migrations/**
- packages/db/src/schema/**
- packages/db/drizzle/**
- scripts/migrate.ts
- .github/workflows/db-migrate.yml
# Auto-apply on merge to main whenever migration-relevant files change, so schema
# changes ship with the code that needs them — no manual workflow_dispatch required.
# The apply is idempotent (skips already-applied migrations via the _raw_migrations
# ledger + drizzle's own ledger), so an unrelated re-run is a no-op.
push:
branches: [main]
paths:
- infra/supabase/migrations/**
- packages/db/src/schema/**
- packages/db/drizzle/**
- scripts/migrate.ts
- .github/workflows/db-migrate.yml
workflow_dispatch:
concurrency:
group: db-migrate
cancel-in-progress: false
jobs:
diff:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
env:
# Empty unless the SUPABASE_MIGRATION_URL secret is configured. Gates the
# connection-dependent migration-plan step below.
MIGRATION_DB_URL: ${{ secrets.SUPABASE_MIGRATION_URL }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 10.33.2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
# drizzle.config.ts imports @cheatcode/env/migrate (built ./dist), so build the db
# package's workspace dep closure before generate — otherwise db:generate fails with
# "Cannot find module @cheatcode/env/dist/migrate.js" on a fresh runner.
- run: pnpm turbo build --filter=@cheatcode/db^...
# drizzle-kit generate reads the schema and never connects; a placeholder URL just
# satisfies drizzle.config.ts's eager loadMigrationEnv() call.
- run: pnpm --filter @cheatcode/db db:generate
env:
SUPABASE_MIGRATION_URL: postgres://placeholder@localhost:5432/placeholder
- name: Fail if Drizzle migrations drifted
run: git diff --exit-code packages/db/drizzle
# The pending-plan comment needs a real DB connection, so it only runs when the
# SUPABASE_MIGRATION_URL secret is configured. The drift check above is the gate;
# this stays best-effort.
- name: Compute pending migration plan
if: env.MIGRATION_DB_URL != ''
run: pnpm tsx scripts/migrate.ts --dry-run | tee migration-plan.txt
env:
SUPABASE_MIGRATION_URL: ${{ env.MIGRATION_DB_URL }}
- uses: marocchino/sticky-pull-request-comment@v2
if: env.MIGRATION_DB_URL != ''
with:
header: db-migration-plan
path: migration-plan.txt
apply:
# Auto on push to main; also available as a manual fallback via workflow_dispatch.
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 10.33.2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
# scripts/migrate.ts spawns drizzle-kit migrate, whose drizzle.config.ts imports
# @cheatcode/env/migrate (built ./dist) — build the db dep closure first.
- run: pnpm turbo build --filter=@cheatcode/db^...
- name: Apply migrations
run: pnpm tsx scripts/migrate.ts --apply
env:
SUPABASE_MIGRATION_URL: ${{ secrets.SUPABASE_MIGRATION_URL }}