const { PrismaClient } = require("@prisma/client"); const prisma = new PrismaClient(); async function main() { const categories = [ { name: "Shoes", slug: "shoes" }, { name: "Bags", slug: "bags" }, { name: "Accessories", slug: "accessories" } ]; for (const category of categories) { await prisma.category.upsert({ where: { slug: category.slug }, update: {}, create: category }); } const shoes = await prisma.category.findUnique({ where: { slug: "shoes" } }); const bags = await prisma.category.findUnique({ where: { slug: "bags" } }); const accessories = await prisma.category.findUnique({ where: { slug: "accessories" } }); const products = [ { categoryId: shoes.id, name: "Street Runner", description: "Lightweight city sneaker.", price: "18990.00", imageUrl: "/images/street-runner.jpg", stock: 24 }, { categoryId: shoes.id, name: "Trail Edge", description: "Stable shoe for outdoor tracks.", price: "24990.00", imageUrl: "/images/trail-edge.jpg", stock: 13 }, { categoryId: bags.id, name: "Urban Tote", description: "Everyday tote with zipper top.", price: "14990.00", imageUrl: "/images/urban-tote.jpg", stock: 30 }, { categoryId: accessories.id, name: "Classic Cap", description: "Adjustable cotton cap.", price: "6990.00", imageUrl: "/images/classic-cap.jpg", stock: 42 } ]; for (const product of products) { await prisma.product.upsert({ where: { name: product.name }, update: {}, create: product }); } } main() .then(async () => { await prisma.$disconnect(); console.log("Prisma seed completed."); }) .catch(async (error) => { console.error(error); await prisma.$disconnect(); process.exit(1); });