- ST-001: Next.js 16 + React 19 + TypeScript strict + Tailwind + shadcn/ui + all deps - ST-002: Prisma v7 setup with better-sqlite3 adapter (local) and pg adapter (cloud) - ST-003: Full schema migration (users, pbis, stories, sprints, tasks, todos, api_tokens) - ST-004: Seed with 9 PBIs, ~40 stories, demo user (demo/demo1234), lars user - ST-005: Zod-validated env vars, .env.example, lib/session, lib/auth, lib/api-auth Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
|
|
function createPrismaClient() {
|
|
const url = process.env.DATABASE_URL
|
|
if (!url) throw new Error('DATABASE_URL is not set')
|
|
|
|
if (url.startsWith('file:')) {
|
|
// SQLite (local development) — use better-sqlite3 adapter
|
|
const { PrismaBetterSqlite3 } = require('@prisma/adapter-better-sqlite3')
|
|
const adapter = new PrismaBetterSqlite3({ url })
|
|
return new PrismaClient({
|
|
adapter,
|
|
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
|
|
})
|
|
}
|
|
|
|
// PostgreSQL (production) — use pg adapter
|
|
const { Pool } = require('pg')
|
|
const { PrismaPg } = require('@prisma/adapter-pg')
|
|
const pool = new Pool({ connectionString: url })
|
|
const adapter = new PrismaPg(pool)
|
|
return new PrismaClient({
|
|
adapter,
|
|
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
|
|
})
|
|
}
|
|
|
|
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined }
|
|
|
|
export const prisma = globalForPrisma.prisma ?? createPrismaClient()
|
|
|
|
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
|