-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.js
More file actions
44 lines (37 loc) · 1.1 KB
/
seed.js
File metadata and controls
44 lines (37 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// server/seed.js
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function main() {
console.log("🌱 Seeding database...");
// Clear old data safely
try {
await prisma.stockMovement.deleteMany();
await prisma.stockItem.deleteMany();
await prisma.location.deleteMany();
await prisma.product.deleteMany();
} catch (e) {
console.log("Database was clean.");
}
// Create Locations with specific IDs matching Frontend
await prisma.location.create({
data: { id: 'loc1', name: 'Main Warehouse', type: 'internal' }
});
await prisma.location.create({
data: { id: 'loc2', name: 'Production Floor', type: 'internal' }
});
// Create Dummy Product
const product = await prisma.product.create({
data: {
name: 'Steel Rods 20mm',
sku: 'ST-2025',
category: 'Raw Material',
cost: 15.00,
price: 25.00
}
});
console.log("✅ Database seeded!");
console.log("👉 Use this Product ID: " + product.id);
}
main()
.catch((e) => console.error(e))
.finally(async () => await prisma.$disconnect());;