diff --git a/backend/prisma/seed.js b/backend/prisma/seed.js new file mode 100644 index 0000000..243bc51 --- /dev/null +++ b/backend/prisma/seed.js @@ -0,0 +1,67 @@ +const { PrismaClient } = require('@prisma/client'); + +const prisma = new PrismaClient(); + +const Role = { + OWNER: 'OWNER', + MANAGER: 'MANAGER', + GROWER: 'GROWER', + STAFF: 'STAFF' +}; + +const RoomType = { + VEG: 'VEG', + FLOWER: 'FLOWER', + DRY: 'DRY', + CURE: 'CURE', + MOTHER: 'MOTHER', + CLONE: 'CLONE' +}; + +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(); + });