fix: Add JS seed script for prod
This commit is contained in:
parent
59b3d9f472
commit
fa89e6feb6
1 changed files with 67 additions and 0 deletions
67
backend/prisma/seed.js
Normal file
67
backend/prisma/seed.js
Normal file
|
|
@ -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();
|
||||||
|
});
|
||||||
Loading…
Add table
Reference in a new issue