phosphat-report-app/prisma/seed.ts

39 lines
960 B
TypeScript

import { PrismaClient } from '@prisma/client'
import bcrypt from 'bcryptjs'
const prisma = new PrismaClient()
async function main() {
console.log('🌱 Seeding database...')
// Seed Employee
//use the .env file SUPER_ADMIN, SUPER_ADMIN_EMAIL and SUPER_ADMIN_PASSWORD
const superAdmin = await prisma.employee.upsert({
where: { username: process.env.SUPER_ADMIN },
update: {},
create: {
name: 'Super Admin User',
authLevel: 3,
username: process.env.SUPER_ADMIN,
email: process.env.SUPER_ADMIN_EMAIL,
password: bcrypt.hashSync(process.env.SUPER_ADMIN_PASSWORD, 10),
status: 'active'
}
})
console.log('✅ Database seeded successfully!')
}
main()
.catch((e) => {
console.error('❌ Error seeding database:', e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})