spomeniV2/prisma/seed.cjs
Dimitar765 d6b29b8e9c
Some checks failed
CI / build (push) Has been cancelled
v2 initial commit
2026-08-03 20:33:49 +02:00

44 lines
1.0 KiB
JavaScript

/* eslint-disable @typescript-eslint/no-require-imports */
const { PrismaClient, Role } = require("@prisma/client");
const prisma = new PrismaClient();
async function main() {
const username = process.env.SUPER_ADMIN_USERNAME || "super";
const hash = process.env.SUPER_ADMIN_PASSWORD_HASH;
if (!hash) {
console.warn(
"[seed] SUPER_ADMIN_PASSWORD_HASH env not set; skipping super-admin provisioning."
);
console.warn(
"[seed] Generate one with: node -e \"import('bcryptjs').then(b => b.default.hash('YOUR_PASSWORD', 12).then(console.log))\""
);
return;
}
await prisma.adminUser.upsert({
where: { username },
update: {
passwordHash: hash,
role: Role.SUPER_ADMIN,
},
create: {
username,
passwordHash: hash,
role: Role.SUPER_ADMIN,
},
});
console.log(`[seed] Super-admin '${username}' provisioned.`);
}
main()
.catch((e) => {
console.error("[seed] failed:", e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});