const mongoose = require('mongoose'); const dotenv = require('dotenv'); dotenv.config(); const User = require('../models/User'); const Product = require('../models/Product'); const Category = require('../models/Category'); const Brand = require('../models/Brand'); const Banner = require('../models/Banner'); const Coupon = require('../models/Coupon'); const WebsiteSettings = require('../models/WebsiteSettings'); const SocialMedia = require('../models/SocialMedia'); const EmailTemplate = require('../models/EmailTemplate'); const Review = require('../models/Review'); const { seedUsers, seedCategories, seedBrands, seedBanners, seedCoupons, seedSocialMedia, seedEmailTemplates } = require('./seedData'); const seedDB = async () => { try { await mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/guitar_ecommerce'); console.log('[SEEDER]: Connected to MongoDB'); // Clear existing collections await User.deleteMany(); await Product.deleteMany(); await Category.deleteMany(); await Brand.deleteMany(); await Banner.deleteMany(); await Coupon.deleteMany(); await WebsiteSettings.deleteMany(); await SocialMedia.deleteMany(); await EmailTemplate.deleteMany(); await Review.deleteMany(); console.log('[SEEDER]: Cleaned old collections'); // 1. Insert Users const users = await User.create(seedUsers); const adminUser = users.find(u => u.role === 'Admin'); const customerUser = users.find(u => u.role === 'Customer'); // 2. Insert Categories const categories = await Category.create(seedCategories); const catMap = {}; categories.forEach(c => { catMap[c.slug] = c._id; }); // 3. Insert Brands const brands = await Brand.create(seedBrands); const brandMap = {}; brands.forEach(b => { brandMap[b.slug] = b._id; }); // 4. Seed Products with INR Prices (₹) and Full Specs const seedProducts = [ { name: 'Fender Player II Stratocaster Electric Guitar', slug: 'fender-player-ii-stratocaster-electric-guitar', sku: 'GTR-2026-10001', brand: brandMap['fender'], category: catMap['electric-guitars'], price: 74999, salePrice: 69999, discountType: 'fixed', discountValue: 5000, stock: 15, description: 'The Fender Player II Stratocaster radiates authentic Fender style and modern playability. Featuring an Alder body, Maple neck with Modern C profile, Rosewood fingerboard, and Alnico V Single-Coil pickups for pristine bell-like highs.', shortDescription: 'Modern C Maple Neck, Alnico V Pickups, Rosewood Fingerboard', images: [ 'https://images.unsplash.com/photo-1564186763535-ebb21ef5277f?w=800', 'https://images.unsplash.com/photo-1550291652-6ea9114a47b1?w=800' ], specs: { guitarType: 'Electric', bodyShape: 'Stratocaster', bodyMaterial: 'Alder', topMaterial: 'None', neckMaterial: 'Maple', fingerboardMaterial: 'Rosewood', scaleLength: '25.5"', numberOfStrings: 6, frets: 22, pickupConfiguration: 'SSS', pickupType: 'Player Series Alnico 5 Single-Coil', bridgeType: '2-Point Synchronized Tremolo with Bent Steel Saddles', tuningMachines: 'Standard Cast/Sealed', handOrientation: 'Right-Handed', color: '3-Color Sunburst', finish: 'Gloss Polyester', includesCase: false }, variants: [ { color: '3-Color Sunburst', colorHex: '#8B4513', finish: 'Gloss', sku: 'GTR-2026-10001-SB', price: 74999, salePrice: 69999, stock: 8 }, { color: 'Polar White', colorHex: '#FFFFFF', finish: 'Gloss', sku: 'GTR-2026-10001-WH', price: 74999, salePrice: 69999, stock: 7 } ], rating: 4.9, numReviews: 24, isFeatured: true, isNewArrival: true, isBestSeller: true }, { name: 'Gibson Les Paul Standard 60s Bourbon Burst', slug: 'gibson-les-paul-standard-60s-bourbon-burst', sku: 'GTR-2026-10002', brand: brandMap['gibson'], category: catMap['electric-guitars'], price: 249999, salePrice: 229999, discountType: 'percentage', discountValue: 8, stock: 6, description: 'The Les Paul Standard 60s has a solid mahogany body with an AA figured maple top and a slim taper 60s-style mahogany neck. Equipped with Burstbucker 61R and 61T humbuckers with Alnico 5 magnets for rich sustain.', shortDescription: 'AA Maple Top, Mahogany Body, Burstbucker 61 Pickups', images: [ 'https://images.unsplash.com/photo-1550291652-6ea9114a47b1?w=800', 'https://images.unsplash.com/photo-1564186763535-ebb21ef5277f?w=800' ], specs: { guitarType: 'Electric', bodyShape: 'Les Paul Singlecut', bodyMaterial: 'Mahogany', topMaterial: 'AA Figured Maple', neckMaterial: 'Mahogany', fingerboardMaterial: 'Indian Rosewood', scaleLength: '24.75"', numberOfStrings: 6, frets: 22, pickupConfiguration: 'HH', pickupType: 'Burstbucker 61R / 61T Humbuckers', bridgeType: 'ABR-1 Tune-O-Matic with Aluminum Stopbar', tuningMachines: 'Grover Rotomatics with Kidney Buttons', handOrientation: 'Right-Handed', color: 'Bourbon Burst', finish: 'Gloss Nitrocellulose Lacquer', includesCase: true }, rating: 5.0, numReviews: 42, isFeatured: true, isBestSeller: true }, { name: 'PRS Custom 24 SE Bonnie Pink', slug: 'prs-custom-24-se-bonnie-pink', sku: 'GTR-2026-10003', brand: brandMap['prs'], category: catMap['electric-guitars'], price: 84999, salePrice: 79999, stock: 12, description: 'The SE Custom 24 brings the original PRS design platform to high-grade instruments. Features a maple top with flame maple veneer, mahogany back, wide thin maple neck, 24 frets, 85/15 "S" humbuckers.', shortDescription: 'Flame Maple Veneer, 85/15 "S" Humbuckers, Bird Inlays', images: ['https://images.unsplash.com/photo-1516924962500-2b4b3b99ea02?w=800'], specs: { guitarType: 'Electric', bodyShape: 'Double Cutaway', bodyMaterial: 'Mahogany', topMaterial: 'Flame Maple Veneer', neckMaterial: 'Maple', fingerboardMaterial: 'Rosewood', scaleLength: '25"', numberOfStrings: 6, frets: 24, pickupConfiguration: 'HH', pickupType: 'PRS 85/15 "S" Humbuckers', bridgeType: 'PRS Patented Tremolo, Molded', tuningMachines: 'PRS Designed Tuners', handOrientation: 'Right-Handed', color: 'Bonnie Pink', finish: 'Gloss Polyurethane', includesCase: true }, rating: 4.8, numReviews: 18, isFeatured: true }, { name: 'Ibanez Genesis Collection RG550 Desert Sun Yellow', slug: 'ibanez-genesis-collection-rg550-desert-sun-yellow', sku: 'GTR-2026-10004', brand: brandMap['ibanez'], category: catMap['electric-guitars'], price: 94999, salePrice: 89999, stock: 8, description: 'Made in Japan, the RG550 features a Basswood body, 5-piece Maple/Walnut Wizard neck, Edge double-locking tremolo system, and V7/S1/V8 pickup combo for lightning-fast solos.', shortDescription: 'Made in Japan, Wizard 5-pc Neck, Edge Tremolo', images: ['https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?w=800'], specs: { guitarType: 'Electric', bodyShape: 'Superstrat / RG', bodyMaterial: 'Basswood', neckMaterial: '5-pc Maple/Walnut', fingerboardMaterial: 'Maple', scaleLength: '25.5"', numberOfStrings: 6, frets: 24, pickupConfiguration: 'HSH', pickupType: 'Ibanez V7 / S1 / V8 Passives', bridgeType: 'Edge Double-Locking Tremolo', tuningMachines: 'Gotoh Machine Heads', handOrientation: 'Right-Handed', color: 'Desert Sun Yellow', finish: 'Gloss', includesCase: false }, rating: 4.9, numReviews: 15, isNewArrival: true }, // ACOUSTIC GUITARS { name: 'Martin D-28 Standard Dreadnought Acoustic Guitar', slug: 'martin-d-28-standard-dreadnought-acoustic-guitar', sku: 'GTR-2026-10005', brand: brandMap['martin'], category: catMap['acoustic-guitars'], price: 289999, salePrice: 269999, stock: 5, description: 'The Martin D-28 is the dreadnought by which all acoustic guitars are judged. Crafted with Solid Sitka Spruce top, East Indian Rosewood back and sides, giving massive projection.', shortDescription: 'Solid Sitka Spruce Top, East Indian Rosewood Back & Sides', images: [ 'https://images.unsplash.com/photo-1525201548942-d8732f6617a0?w=800', 'https://images.unsplash.com/photo-1510915361894-db8b60106cb1?w=800' ], specs: { guitarType: 'Acoustic', bodyShape: 'Dreadnought', bodyMaterial: 'East Indian Rosewood', topMaterial: 'Solid Sitka Spruce', neckMaterial: 'Select Hardwood', fingerboardMaterial: 'Ebony', scaleLength: '25.4"', numberOfStrings: 6, frets: 20, pickupConfiguration: 'None', bridgeType: 'Ebony Modern Belly', tuningMachines: 'Nickel Open Gear', handOrientation: 'Right-Handed', color: 'Natural Spruce', finish: 'Gloss Natural', includesCase: true }, rating: 5.0, numReviews: 31, isFeatured: true, isBestSeller: true }, { name: 'Taylor 214ce Grand Auditorium Acoustic-Electric', slug: 'taylor-214ce-grand-auditorium-acoustic-electric-guitar', sku: 'GTR-2026-10006', brand: brandMap['taylor'], category: catMap['acoustic-guitars'], price: 109999, salePrice: 99999, stock: 9, description: 'Combines a solid Torrefied Sitka Spruce top with layered Rosewood back and sides for rich acoustic balance. Includes Taylor ES2 electronics.', shortDescription: 'Torrefied Spruce Top, ES2 Electronics, Venetian Cutaway', images: ['https://images.unsplash.com/photo-1510915361894-db8b60106cb1?w=800'], specs: { guitarType: 'Acoustic', bodyShape: 'Grand Auditorium Cutaway', bodyMaterial: 'Layered Rosewood', topMaterial: 'Solid Sitka Spruce', neckMaterial: 'Neo-Tropical Mahogany', fingerboardMaterial: 'West African Ebony', scaleLength: '25.5"', numberOfStrings: 6, frets: 20, pickupConfiguration: 'Taylor Expression System 2 (ES2)', bridgeType: 'Ebony', tuningMachines: 'Taylor Chrome Tuners', handOrientation: 'Right-Handed', color: 'Natural', finish: 'Matte Finish', includesCase: true }, rating: 4.8, numReviews: 19, isNewArrival: true }, { name: 'Yamaha FG800 Solid Top Dreadnought Acoustic', slug: 'yamaha-fg800-solid-top-dreadnought-acoustic-guitar', sku: 'GTR-2026-10007', brand: brandMap['yamaha'], category: catMap['acoustic-guitars'], price: 19999, salePrice: 17999, stock: 25, description: 'Yamaha’s flagship entry-level acoustic with solid Sitka spruce top, nato back and sides, scalloped bracing for enhanced low-end.', shortDescription: 'Solid Sitka Spruce Top, Scalloped Bracing', images: ['https://images.unsplash.com/photo-1510915361894-db8b60106cb1?w=800'], specs: { guitarType: 'Acoustic', bodyShape: 'Dreadnought', bodyMaterial: 'Nato / Okoume', topMaterial: 'Solid Sitka Spruce', neckMaterial: 'Nato', fingerboardMaterial: 'Rosewood', scaleLength: '25"', numberOfStrings: 6, frets: 20, pickupConfiguration: 'None', bridgeType: 'Rosewood', tuningMachines: 'Die-Cast Chrome', handOrientation: 'Right-Handed', color: 'Natural', finish: 'Gloss', includesCase: false }, rating: 4.9, numReviews: 67, isBestSeller: true }, // BASS GUITARS { name: 'Fender Player II Precision Bass Olympic White', slug: 'fender-player-ii-precision-bass-olympic-white', sku: 'GTR-2026-10008', brand: brandMap['fender'], category: catMap['bass-guitars'], price: 79999, salePrice: 74999, stock: 7, description: 'Features a punchy Player Series Split Single-Coil pickup, Modern C maple neck, 9.5"-radius rosewood fingerboard for definitive Fender low-end.', shortDescription: 'Split Single-Coil Pickup, Modern C Neck, Long Scale', images: ['https://images.unsplash.com/photo-1564186763535-ebb21ef5277f?w=800'], specs: { guitarType: 'Bass', bodyShape: 'Precision Bass', bodyMaterial: 'Alder', topMaterial: 'None', neckMaterial: 'Maple', fingerboardMaterial: 'Rosewood', scaleLength: '34" Long Scale', numberOfStrings: 4, frets: 20, pickupConfiguration: 'Split Single-Coil', pickupType: 'Player Series Alnico 5 Split-Coil', bridgeType: '4-Saddle Standard', tuningMachines: 'Standard Open-Gear', handOrientation: 'Right-Handed', color: 'Olympic White', finish: 'Gloss Polyester', includesCase: false }, rating: 4.9, numReviews: 11, isNewArrival: true }, // AMPLIFIERS & PEDALS { name: 'Boss Katana-100 MkII 100-watt 1x12 Combo Amp', slug: 'boss-katana-100-mkii-combo-amplifier', sku: 'GTR-2026-10009', brand: brandMap['boss'], category: catMap['amplifiers'], price: 36999, salePrice: 33999, stock: 20, description: 'Five primary amp characters with five variation options, plus 60 customizable Boss effects accessible via BOSS Tone Studio software.', shortDescription: '100W Output, 12" Custom Speaker, 60 BOSS Effects', images: ['https://images.unsplash.com/photo-1598488035139-bdbb2231ce04?w=800'], specs: { guitarType: 'Accessories', bodyShape: 'Combo Amp', finish: 'Black Tolex', includesCase: false }, rating: 4.9, numReviews: 54, isBestSeller: true } ]; const insertedProducts = await Product.create(seedProducts); console.log(`[SEEDER]: Inserted ${insertedProducts.length} realistic INR products with SKUs & specs`); // 5. Insert Banners, Coupons, SocialMedia, EmailTemplates, WebsiteSettings await Banner.create(seedBanners); await Coupon.create(seedCoupons); await SocialMedia.create(seedSocialMedia); await EmailTemplate.create(seedEmailTemplates); await WebsiteSettings.create({}); // 6. Demo Reviews await Review.create([ { user: customerUser._id, product: insertedProducts[0]._id, rating: 5, title: 'Sensational playability!', comment: 'The Player II Stratocaster neck feels like butter. Clean tones ring out beautifully.' }, { user: customerUser._id, product: insertedProducts[1]._id, rating: 5, title: 'Dream guitar achieved in India!', comment: 'The Les Paul Standard 60s in Bourbon Burst has unbeatable sustain. Fast delivery in Bengaluru!' } ]); console.log('===================================================='); console.log('[SEED COMPLETE]: Database fully populated!'); console.log('Admin Email: admin@guitars.com | Password: Admin@123'); console.log('Customer Email: john@example.com | Password: Customer@123'); console.log('===================================================='); process.exit(0); } catch (error) { console.error('[SEED ERROR]:', error); process.exit(1); } }; seedDB();