diff --git a/AGENTS.md b/AGENTS.md index 8109df49..d44fc05b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,12 +15,12 @@ Dispatch is a self-hosted Next.js/TypeScript Kanban and work dispatch layer for ## Key Commands ```bash -npm install # Install dependencies +npm install # Install dependencies (runs `prisma generate` via postinstall) npm run dev # Start development server npm run build # Production build npm run lint # Lint check npm run typecheck # TypeScript check -npx prisma generate # Generate Prisma client +npm run db:generate # Regenerate Prisma client (also runs on postinstall; re-run after editing schema.prisma) npm run db:push # Push schema (dev) npm run db:deploy # Deploy migrations (prod) ``` diff --git a/package.json b/package.json index 34ffcb2b..9e2bb595 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "test:watch": "NODE_ENV=development vitest", "test:coverage": "NODE_ENV=development vitest run --coverage", "typecheck": "NODE_ENV=development tsc --noEmit", + "postinstall": "test -f prisma/schema.prisma && prisma generate || true", "db:generate": "prisma generate", "db:push": "prisma db push", "db:migrate": "prisma migrate dev", diff --git a/prisma.config.ts b/prisma.config.ts index 42236169..410a1935 100644 --- a/prisma.config.ts +++ b/prisma.config.ts @@ -1,16 +1,14 @@ import { defineConfig } from "prisma/config"; +// NOTE: do not throw when DATABASE_URL is unset. This config is loaded by every +// Prisma CLI invocation, including `prisma generate` (run on postinstall), which +// needs only the schema — not a live datasource URL. Throwing here broke fresh +// clones: `npm install` -> postinstall -> generate -> throw. The datasource URL +// is supplied only when present (for migrate/deploy/studio); the app enforces +// DATABASE_URL at runtime via src/lib/prisma.ts. 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", - datasource: { - url: databaseUrl, - }, + ...(databaseUrl ? { datasource: { url: databaseUrl } } : {}), });