35 lines
826 B
TypeScript
35 lines
826 B
TypeScript
import { PrismaClient } from "@prisma/client";
|
|
import { hash } from "bcryptjs";
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log("Seeding database...");
|
|
|
|
const adminEmail = process.env.ADMIN_EMAIL || "admin@ando.dev";
|
|
const rawPassword = process.env.ADMIN_PASSWORD || "admin123";
|
|
const passwordHash = await hash(rawPassword, 12);
|
|
|
|
// Upsert ensures we don't insert duplicate admins if the seeder runs twice
|
|
const user = await prisma.user.upsert({
|
|
where: { email: adminEmail },
|
|
update: {},
|
|
create: {
|
|
email: adminEmail,
|
|
name: "Yolando Admin",
|
|
passwordHash,
|
|
},
|
|
});
|
|
|
|
console.log(`Admin user created: ${user.email}`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|