From c7f22a09908e48eb64ab442bdbbb3b202b7f41ca Mon Sep 17 00:00:00 2001 From: adilallo <39313955+adilallo@users.noreply.github.com> Date: Tue, 21 Apr 2026 22:48:23 -0600 Subject: [PATCH] CI: Postgres migration smoke --- .gitea/workflows/migrate-smoke.yaml | 74 +++++++++++++++++++++++++++++ CONTRIBUTING.md | 10 ++++ 2 files changed, 84 insertions(+) create mode 100644 .gitea/workflows/migrate-smoke.yaml diff --git a/.gitea/workflows/migrate-smoke.yaml b/.gitea/workflows/migrate-smoke.yaml new file mode 100644 index 0000000..73b5796 --- /dev/null +++ b/.gitea/workflows/migrate-smoke.yaml @@ -0,0 +1,74 @@ +name: Migrate Smoke +run-name: "${{ gitea.actor }} triggered migrate smoke" + +on: + workflow_dispatch: {} + pull_request: + branches: [main] + paths: + - "prisma/**" + - ".gitea/workflows/migrate-smoke.yaml" + push: + branches: [main] + paths: + - "prisma/**" + - ".gitea/workflows/migrate-smoke.yaml" + +env: + NODE_VERSION: "20" + NEXT_TELEMETRY_DISABLED: "1" + # Non-default host port so a local dev Postgres on 5432 keeps working. + PG_HOST_PORT: "5433" + POSTGRES_USER: communityrule + POSTGRES_PASSWORD: communityrule + POSTGRES_DB: communityrule + +jobs: + migrate: + runs-on: [self-hosted, macos-latest] + env: + CI: true + DATABASE_URL: "postgresql://communityrule:communityrule@127.0.0.1:5433/communityrule" + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "${{ env.NODE_VERSION }}" + cache: npm + + - name: Start Postgres + run: | + set -euo pipefail + docker rm -f migrate-smoke-pg >/dev/null 2>&1 || true + docker run -d --name migrate-smoke-pg \ + -e POSTGRES_USER="$POSTGRES_USER" \ + -e POSTGRES_PASSWORD="$POSTGRES_PASSWORD" \ + -e POSTGRES_DB="$POSTGRES_DB" \ + -p "${PG_HOST_PORT}:5432" \ + postgres:16-alpine + + - name: Wait for Postgres + run: | + set -euo pipefail + for i in {1..30}; do + if docker exec migrate-smoke-pg pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" >/dev/null 2>&1; then + echo "Postgres ready after ${i}s" + exit 0 + fi + sleep 1 + done + echo "Postgres did not become ready in 30s" + docker logs migrate-smoke-pg || true + exit 1 + + - run: npm ci --no-audit --fund=false + + - name: Apply migrations + run: npm run db:deploy + + - name: Verify Prisma can connect to migrated DB + run: echo "SELECT 1;" | npx --no-install prisma db execute --stdin --url "$DATABASE_URL" + + - name: Stop Postgres + if: always() + run: docker rm -f migrate-smoke-pg >/dev/null 2>&1 || true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0e46bd5..d3938f8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,6 +21,16 @@ Use `npx prisma studio` to inspect the database. production, or any shared database. Add a **new** migration that corrects the schema instead. Full policy: [docs/guides/backend-roadmap.md](docs/guides/backend-roadmap.md) ยง8. +- **CI smoke:** [`.gitea/workflows/migrate-smoke.yaml`](.gitea/workflows/migrate-smoke.yaml) + spins up a throwaway Postgres and runs `npm run db:deploy` whenever + `prisma/**` changes on a PR (or via `workflow_dispatch`). If the + runner cannot run Docker/Postgres, run the same check locally before + merging migration changes: + + ```bash + docker compose up -d postgres + npm run db:deploy + ``` ### API routes