42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import { PrismaClient } from '@prisma/client';
|
|
import bcrypt from 'bcryptjs';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('🌱 Seeding database...');
|
|
|
|
|
|
// Seed Super Admin Employee
|
|
const superAdminUsername = process.env.SUPER_ADMIN || 'superadmin';
|
|
const superAdminEmail = process.env.SUPER_ADMIN_EMAIL || 'admin@example.com';
|
|
const superAdminPassword = process.env.SUPER_ADMIN_PASSWORD || 'P@ssw0rd123';
|
|
|
|
await prisma.employee.upsert({
|
|
where: { username: superAdminUsername },
|
|
update: {},
|
|
create: {
|
|
name: 'Super Admin User',
|
|
authLevel: 3,
|
|
username: superAdminUsername,
|
|
email: superAdminEmail,
|
|
password: bcrypt.hashSync(superAdminPassword, 10)
|
|
}
|
|
});
|
|
|
|
|
|
|
|
console.log('✅ Database seeded successfully!');
|
|
|
|
console.log(`Created 1 employee`);
|
|
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error('❌ Error seeding database:', e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
}); |