diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 615ed5e..d4b937e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,6 +21,8 @@ jobs: validate: name: Validate runs-on: ubuntu-latest + env: + DATABASE_URL: "postgresql://test:test@localhost:5432/dispatch_ci" steps: - name: Checkout uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 diff --git a/.github/workflows/image.yaml b/.github/workflows/image.yaml index 1192008..6173482 100644 --- a/.github/workflows/image.yaml +++ b/.github/workflows/image.yaml @@ -63,14 +63,16 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + build-args: | + DATABASE_URL=postgresql://localhost:5432/dispatch - name: Validate Prisma CLI runtime run: | IMAGE="dispatch:prisma-cli-runtime" docker build -t "$IMAGE" . echo "Validating Prisma CLI in image: $IMAGE" - docker run --rm --entrypoint ./node_modules/.bin/prisma "$IMAGE" --version - docker run --rm --entrypoint ./node_modules/.bin/prisma "$IMAGE" validate + docker run --rm --env DATABASE_URL=postgresql://localhost:5432/dispatch --entrypoint ./node_modules/.bin/prisma "$IMAGE" --version + docker run --rm --env DATABASE_URL=postgresql://localhost:5432/dispatch --entrypoint ./node_modules/.bin/prisma "$IMAGE" validate - name: Run Trivy vulnerability scanner if: github.event_name != 'pull_request' diff --git a/Dockerfile b/Dockerfile index 7c3b883..0a6711c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ RUN npm ci --omit=dev FROM base AS builder WORKDIR /app +ARG DATABASE_URL=postgresql://localhost:5432/dispatch COPY --from=deps /app/node_modules ./node_modules COPY . . RUN apt-get update && apt-get install -y --no-install-recommends openssl ca-certificates && rm -rf /var/lib/apt/lists/* diff --git a/prisma.config.ts b/prisma.config.ts index a356555..4223616 100644 --- a/prisma.config.ts +++ b/prisma.config.ts @@ -1,7 +1,12 @@ import { defineConfig } from "prisma/config"; -const databaseUrl = - process.env.DATABASE_URL ?? "postgresql://dispatch:dispatch@localhost:5432/dispatch"; +const databaseUrl = process.env.DATABASE_URL; + +if (!databaseUrl) { + throw new Error( + "DATABASE_URL is not set. Please set the DATABASE_URL environment variable before starting the application.", + ); +} export default defineConfig({ schema: "prisma/schema.prisma", diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index 442a2be..48460a4 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -3,8 +3,13 @@ import { PrismaPg } from "@prisma/adapter-pg"; import { PrFixQueueClient } from "@/lib/pr-fix-queue"; import { AgentWorkClient } from "@/lib/agent-work"; -const databaseUrl = - process.env.DATABASE_URL ?? "postgresql://dispatch:dispatch@localhost:5432/dispatch"; +const databaseUrl = process.env.DATABASE_URL; + +if (!databaseUrl) { + throw new Error( + "DATABASE_URL is not set. Please set the DATABASE_URL environment variable before starting the application.", + ); +} const adapter = new PrismaPg(databaseUrl); diff --git a/vitest.setup.ts b/vitest.setup.ts index 39d6b24..879fd0d 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -1,6 +1,10 @@ // Import @testing-library/jest-dom/vitest for custom matchers import "@testing-library/jest-dom/vitest"; +// Provide a dummy DATABASE_URL so prisma.ts module loads without throwing. +// Tests that need real DB access mock/override as needed. +process.env.DATABASE_URL ??= "postgresql://test:test@localhost:5432/dispatch_test"; + // Patch React.act for React 19 + @testing-library/react v16 compat. // React 19 removed React.act, but older react-dom/test-utils still calls it. const React = require("react");