- Models: User, Session, FlowRun, FlowStep met FlowStatus enum - prisma.config.ts met DATABASE_URL via @prisma/adapter-pg (Prisma 7 API) - Initiële migratie applied op ops_dashboard database - Seed-script voor 1 user via SEED_USER_EMAIL/SEED_USER_PASSWORD env-vars - lib/prisma.ts als gedeelde singleton client voor Next.js Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
35 lines
930 B
TypeScript
35 lines
930 B
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
import { PrismaPg } from '@prisma/adapter-pg'
|
|
import bcrypt from 'bcryptjs'
|
|
|
|
const connectionString = process.env.DATABASE_URL
|
|
if (!connectionString) throw new Error('DATABASE_URL is required')
|
|
|
|
const adapter = new PrismaPg({ connectionString })
|
|
const prisma = new PrismaClient({ adapter })
|
|
|
|
async function main() {
|
|
const email = process.env.SEED_USER_EMAIL
|
|
const password = process.env.SEED_USER_PASSWORD
|
|
|
|
if (!email || !password) {
|
|
throw new Error('SEED_USER_EMAIL and SEED_USER_PASSWORD env vars are required')
|
|
}
|
|
|
|
const pwd_hash = await bcrypt.hash(password, 12)
|
|
|
|
const user = await prisma.user.upsert({
|
|
where: { email },
|
|
update: { pwd_hash },
|
|
create: { email, pwd_hash },
|
|
})
|
|
|
|
console.log(`Seeded user: ${user.email} (id: ${user.id})`)
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e)
|
|
process.exit(1)
|
|
})
|
|
.finally(() => prisma.$disconnect())
|