diff --git a/backend/prisma/seed-demo.js b/backend/prisma/seed-demo.js index b82eaad..0b82b76 100644 --- a/backend/prisma/seed-demo.js +++ b/backend/prisma/seed-demo.js @@ -74,6 +74,109 @@ async function main() { rooms[r.name.replace(DEMO_PREFIX + ' ', '')] = room; } + // ==================== FACILITY STRUCTURE ==================== + console.log('\nšŸ—ļø Creating Facility Structure...'); + + // Create Property + let property = await prisma.facilityProperty.findFirst({ where: { name: `${DEMO_PREFIX} 777 Wolfpack Cultivation` } }); + if (!property) { + property = await prisma.facilityProperty.create({ + data: { + name: `${DEMO_PREFIX} 777 Wolfpack Cultivation`, + address: '1234 Grow Lane, Grass Valley, CA 95945', + licenseNum: 'CCL21-0001234' + } + }); + console.log(' āœ“ Property: 777 Wolfpack Cultivation'); + } + + // Create Buildings + const buildingsData = [ + { name: 'Main Cultivation', code: 'GROW1', type: 'CULTIVATION' }, + { name: 'Processing Facility', code: 'PROC1', type: 'PROCESSING' }, + ]; + + const buildings = {}; + for (const b of buildingsData) { + let building = await prisma.facilityBuilding.findFirst({ + where: { code: b.code, propertyId: property.id } + }); + if (!building) { + building = await prisma.facilityBuilding.create({ + data: { ...b, propertyId: property.id } + }); + console.log(` āœ“ Building: ${b.name}`); + } + buildings[b.code] = building; + } + + // Create Floors + const floorsData = [ + { buildingCode: 'GROW1', name: 'Ground Floor', number: 1, width: 100, height: 80, ceilingHeight: 12 }, + { buildingCode: 'GROW1', name: 'Upper Floor', number: 2, width: 100, height: 80, ceilingHeight: 10 }, + { buildingCode: 'PROC1', name: 'Ground Floor', number: 1, width: 60, height: 40, ceilingHeight: 10 }, + ]; + + const floors = {}; + for (const f of floorsData) { + const buildingId = buildings[f.buildingCode]?.id; + if (!buildingId) continue; + + let floor = await prisma.facilityFloor.findFirst({ + where: { number: f.number, buildingId } + }); + if (!floor) { + floor = await prisma.facilityFloor.create({ + data: { + buildingId, + name: f.name, + number: f.number, + width: f.width, + height: f.height, + ceilingHeight: f.ceilingHeight + } + }); + console.log(` āœ“ Floor: ${f.buildingCode} - ${f.name}`); + } + floors[`${f.buildingCode}-F${f.number}`] = floor; + } + + // Create Facility Rooms (mapped to grow rooms) + const facilityRoomsData = [ + { floorKey: 'GROW1-F1', name: 'Veg Room 1', code: 'VEG-A', type: 'VEG', posX: 10, posY: 10, width: 40, height: 30 }, + { floorKey: 'GROW1-F1', name: 'Veg Room 2', code: 'VEG-B', type: 'VEG', posX: 55, posY: 10, width: 35, height: 25 }, + { floorKey: 'GROW1-F1', name: 'Mother Room', code: 'MTHR', type: 'MOTHER', posX: 10, posY: 45, width: 20, height: 20 }, + { floorKey: 'GROW1-F2', name: 'Flower Room A', code: 'FLR-A', type: 'FLOWER', posX: 5, posY: 5, width: 45, height: 35 }, + { floorKey: 'GROW1-F2', name: 'Flower Room B', code: 'FLR-B', type: 'FLOWER', posX: 52, posY: 5, width: 45, height: 35 }, + { floorKey: 'GROW1-F2', name: 'Flower Room C', code: 'FLR-C', type: 'FLOWER', posX: 5, posY: 42, width: 40, height: 30 }, + { floorKey: 'PROC1-F1', name: 'Dry Room', code: 'DRY', type: 'DRY', posX: 5, posY: 5, width: 25, height: 30 }, + { floorKey: 'PROC1-F1', name: 'Cure Room', code: 'CURE', type: 'CURE', posX: 35, posY: 5, width: 20, height: 30 }, + ]; + + for (const fr of facilityRoomsData) { + const floorId = floors[fr.floorKey]?.id; + if (!floorId) continue; + + const existing = await prisma.facilityRoom.findFirst({ + where: { code: fr.code, floorId } + }); + if (!existing) { + await prisma.facilityRoom.create({ + data: { + floorId, + name: fr.name, + code: fr.code, + type: fr.type, + posX: fr.posX, + posY: fr.posY, + width: fr.width, + height: fr.height + } + }); + } + } + console.log(' āœ“ 8 facility rooms mapped'); + // ==================== BATCHES ==================== console.log('\n🌱 Creating Batches...'); const batchesData = [