const { PrismaClient } = require("@prisma/client"); const bcryptjs = require("bcryptjs"); const prisma = new PrismaClient(); async function main() { console.log("Starting database seeding..."); // Seed categories const categories = [ { name: "Shoes", slug: "shoes" }, { name: "Bags", slug: "bags" }, { name: "Accessories", slug: "accessories" }, { name: "Clothing", slug: "clothing" }, { name: "Electronics", slug: "electronics" } ]; console.log("Creating categories..."); 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 clothing = await prisma.category.findUnique({ where: { slug: "clothing" } }); const electronics = await prisma.category.findUnique({ where: { slug: "electronics" } }); const products = [ // Shoes { categoryId: shoes.id, name: "Street Runner", description: "Lightweight city sneaker perfect for daily commute.", price: "18990.00", imageUrl: "/images/street-runner.jpg", stock: 24 }, { categoryId: shoes.id, name: "Trail Edge", description: "Stable shoe for outdoor tracks and hiking adventures.", price: "24990.00", imageUrl: "/images/trail-edge.jpg", stock: 13 }, { categoryId: shoes.id, name: "Urban Sprint", description: "High-performance running shoe for athletes.", price: "22990.00", imageUrl: "/images/urban-sprint.jpg", stock: 18 }, { categoryId: shoes.id, name: "Classic Comfort", description: "Timeless design with ultimate comfort for all-day wear.", price: "16990.00", imageUrl: "/images/classic-comfort.jpg", stock: 31 }, // Bags { categoryId: bags.id, name: "Urban Tote", description: "Everyday tote with zipper top and multiple compartments.", price: "14990.00", imageUrl: "/images/urban-tote.jpg", stock: 30 }, { categoryId: bags.id, name: "Backpack Pro", description: "Professional backpack with laptop compartment.", price: "19990.00", imageUrl: "/images/backpack-pro.jpg", stock: 15 }, { categoryId: bags.id, name: "Crossbody Essentials", description: "Compact crossbody bag perfect for quick trips.", price: "9990.00", imageUrl: "/images/crossbody.jpg", stock: 45 }, { categoryId: bags.id, name: "Weekend Duffle", description: "Spacious duffle bag for travel and weekend getaways.", price: "24990.00", imageUrl: "/images/duffle.jpg", stock: 8 }, // Accessories { categoryId: accessories.id, name: "Classic Cap", description: "Adjustable cotton cap with curved visor.", price: "6990.00", imageUrl: "/images/classic-cap.jpg", stock: 42 }, { categoryId: accessories.id, name: "Silk Scarf", description: "Premium silk scarf with elegant patterns.", price: "12990.00", imageUrl: "/images/silk-scarf.jpg", stock: 20 }, { categoryId: accessories.id, name: "Leather Belt", description: "Genuine leather belt with metal buckle.", price: "8990.00", imageUrl: "/images/leather-belt.jpg", stock: 35 }, { categoryId: accessories.id, name: "Watch Straps Set", description: "Set of 3 interchangeable watch straps.", price: "4990.00", imageUrl: "/images/watch-straps.jpg", stock: 60 }, // Clothing { categoryId: clothing.id, name: "Cotton T-Shirt", description: "100% organic cotton comfortable t-shirt.", price: "7990.00", imageUrl: "/images/cotton-tshirt.jpg", stock: 50 }, { categoryId: clothing.id, name: "Denim Jacket", description: "Classic blue denim jacket perfect for any season.", price: "29990.00", imageUrl: "/images/denim-jacket.jpg", stock: 12 }, { categoryId: clothing.id, name: "Yoga Leggings", description: "High-waisted leggings with optimal breathability.", price: "11990.00", imageUrl: "/images/yoga-leggings.jpg", stock: 25 }, // Electronics { categoryId: electronics.id, name: "Wireless Earbuds", description: "Premium noise-cancelling wireless earbuds.", price: "17990.00", imageUrl: "/images/earbuds.jpg", stock: 22 }, { categoryId: electronics.id, name: "USB-C Hub", description: "7-in-1 USB-C hub with multiple ports.", price: "5990.00", imageUrl: "/images/usb-hub.jpg", stock: 40 } ]; console.log("Creating products..."); for (const product of products) { await prisma.product.upsert({ where: { name: product.name }, update: {}, create: product }); } // Seed test users console.log("Creating test users..."); const testUsers = [ { name: "Admin User", email: "admin@test.com", password: "admin123" }, { name: "John Doe", email: "john@test.com", password: "password123" }, { name: "Jane Smith", email: "jane@test.com", password: "password123" } ]; for (const user of testUsers) { const passwordHash = await bcryptjs.hash(user.password, 10); await prisma.user.upsert({ where: { email: user.email }, update: {}, create: { name: user.name, email: user.email, passwordHash } }); } console.log("Database seeding completed successfully!"); } main() .then(async () => { await prisma.$disconnect(); }) .catch(async (error) => { console.error("Seeding error:", error); await prisma.$disconnect(); process.exit(1); });