first build commit
This commit is contained in:
31
prisma/seed.ts
Normal file
31
prisma/seed.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Pool } from 'pg'
|
||||
import { PrismaPg } from '@prisma/adapter-pg'
|
||||
import { PrismaClient } from '../src/generated/prisma/client'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
|
||||
const adapter = new PrismaPg(pool)
|
||||
const prisma = new PrismaClient({ adapter })
|
||||
|
||||
async function main() {
|
||||
const email = process.env.SEED_EMAIL
|
||||
const password = process.env.SEED_PASSWORD
|
||||
|
||||
if (!email || !password) {
|
||||
throw new Error('SEED_EMAIL and SEED_PASSWORD must be set in .env')
|
||||
}
|
||||
|
||||
const passwordHash = await bcrypt.hash(password, 12)
|
||||
|
||||
const user = await prisma.user.upsert({
|
||||
where: { email },
|
||||
update: { passwordHash },
|
||||
create: { email, passwordHash },
|
||||
})
|
||||
|
||||
console.log(`Seeded user: ${user.email}`)
|
||||
}
|
||||
|
||||
main()
|
||||
.catch(console.error)
|
||||
.finally(() => prisma.$disconnect())
|
||||
Reference in New Issue
Block a user