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())