erp_be/prisma/seed.js
2026-06-17 11:30:11 +05:30

50 lines
1.2 KiB
JavaScript

/* eslint-disable no-console */
const { PrismaClient } = require('@prisma/client');
const bcrypt = require('bcrypt');
const prisma = new PrismaClient();
async function main() {
const superAdminRole = await prisma.roles.findFirst({
where: { name: 'Super Admin', deleted_at: null },
});
if (!superAdminRole) {
throw new Error('Super Admin role not found. Run erp_phase1_ddl.sql first.');
}
const passwordHash = await bcrypt.hash('Admin@123', 12);
await prisma.users.upsert({
where: { email: 'admin@bharaterp.com' },
update: {
role_id: superAdminRole.id,
status: 'active',
is_active: true,
deleted_at: null,
},
create: {
employee_code: 'EMP001',
full_name: 'Super Admin',
email: 'admin@bharaterp.com',
password_hash: passwordHash,
role_id: superAdminRole.id,
status: 'active',
is_active: true,
},
});
console.log('Bootstrap Super Admin ready: admin@bharaterp.com / Admin@123');
}
main()
.then(async () => {
await prisma.$disconnect();
process.exit(0);
})
.catch(async (err) => {
console.error('Seed failed', err);
await prisma.$disconnect();
process.exit(1);
});