51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { PrismaClient, Role, RoomType } from '@prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('Seeding database...');
|
|
|
|
// Create Owner
|
|
const ownerEmail = 'admin@runfoo.com';
|
|
const existingOwner = await prisma.user.findUnique({ where: { email: ownerEmail } });
|
|
|
|
if (!existingOwner) {
|
|
await prisma.user.create({
|
|
data: {
|
|
email: ownerEmail,
|
|
passwordHash: 'password123', // In real app, hash this
|
|
name: 'Facility Owner',
|
|
role: Role.OWNER,
|
|
rate: 50.00
|
|
}
|
|
});
|
|
console.log('Created Owner: admin@runfoo.com / password123');
|
|
}
|
|
|
|
// Create Default Rooms
|
|
const rooms = [
|
|
{ name: 'Veg Room 1', type: RoomType.VEG, sqft: 1200 },
|
|
{ name: 'Flower Room A', type: RoomType.FLOWER, sqft: 2500 },
|
|
{ name: 'Flower Room B', type: RoomType.FLOWER, sqft: 2500 },
|
|
{ name: 'Dry Room', type: RoomType.DRY, sqft: 800 },
|
|
];
|
|
|
|
for (const r of rooms) {
|
|
const existing = await prisma.room.findFirst({ where: { name: r.name } });
|
|
if (!existing) {
|
|
await prisma.room.create({ data: r });
|
|
console.log(`Created Room: ${r.name}`);
|
|
}
|
|
}
|
|
|
|
console.log('Seeding complete.');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|