54 lines
1.1 KiB
TypeScript
54 lines
1.1 KiB
TypeScript
|
|
import { PrismaClient } from "@prisma/client";
|
||
|
|
import bcrypt from "bcryptjs";
|
||
|
|
|
||
|
|
const prisma = new PrismaClient();
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
// Seed roles
|
||
|
|
const ownerRole = await prisma.role.upsert({
|
||
|
|
where: { name: "owner" },
|
||
|
|
update: {},
|
||
|
|
create: { name: "owner" },
|
||
|
|
});
|
||
|
|
await prisma.role.upsert({
|
||
|
|
where: { name: "manager" },
|
||
|
|
update: {},
|
||
|
|
create: { name: "manager" },
|
||
|
|
});
|
||
|
|
await prisma.role.upsert({
|
||
|
|
where: { name: "cashier" },
|
||
|
|
update: {},
|
||
|
|
create: { name: "cashier" },
|
||
|
|
});
|
||
|
|
|
||
|
|
// Seed demo vendor
|
||
|
|
const vendor = await prisma.vendor.upsert({
|
||
|
|
where: { id: "demo-vendor" },
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
id: "demo-vendor",
|
||
|
|
name: "Demo Store",
|
||
|
|
businessNum: "123-456",
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
// Seed demo owner user
|
||
|
|
await prisma.user.upsert({
|
||
|
|
where: { email: "admin@demo.com" },
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
email: "admin@demo.com",
|
||
|
|
passwordHash: await bcrypt.hash("password123", 10),
|
||
|
|
name: "Demo Admin",
|
||
|
|
vendorId: vendor.id,
|
||
|
|
roleId: ownerRole.id,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log("Seed complete");
|
||
|
|
}
|
||
|
|
|
||
|
|
main()
|
||
|
|
.catch(console.error)
|
||
|
|
.finally(() => prisma.$disconnect());
|