Files
monitoring-app/prisma/seed.ts
amal c66ce4a39b upd: auth
Deskripsi:
-update login
- update struktur database

No Issues
2026-04-15 11:17:04 +08:00

53 lines
1.5 KiB
TypeScript

import { PrismaClient } from '../generated/prisma'
const prisma = new PrismaClient()
const SUPER_ADMIN_EMAILS = (process.env.SUPER_ADMIN_EMAIL ?? '').split(',').map(e => e.trim()).filter(Boolean)
async function main() {
const users = [
{ name: 'Admin', email: 'admin@example.com', password: 'admin123', role: 'ADMIN' as const },
]
for (const u of users) {
const hashed = await Bun.password.hash(u.password, { algorithm: 'bcrypt' })
await prisma.user.upsert({
where: { email: u.email },
update: { name: u.name, password: hashed, role: u.role },
create: { name: u.name, email: u.email, password: hashed, role: u.role },
})
console.log(`Seeded: ${u.email} (${u.role})`)
}
// Promote DEVELOPER emails from env
for (const email of SUPER_ADMIN_EMAILS) {
const password = await Bun.password.hash('developer123', { algorithm: 'bcrypt' })
await prisma.user.upsert({
where: { email },
update: { role: 'DEVELOPER', password },
create: { name: email.split('@')[0].toUpperCase(), email, password, role: 'DEVELOPER' },
})
console.log(`Promoted to DEVELOPER: ${email}`)
}
const apps = [
{ id: 'desa-plus', name: 'Desa+' },
]
for (const a of apps) {
await prisma.app.upsert({
where: { id: a.id },
update: { name: a.name },
create: { id: a.id, name: a.name },
})
console.log(`Seeded: ${a.name}`)
}
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(() => prisma.$disconnect())