# Database Seeding Guide This directory contains seed data scripts for populating your e-commerce database with sample data. ## Prerequisites Before running the seed script, make sure you have: 1. **Database configured**: Update your `.env` file with correct database credentials 2. **Dependencies installed**: Run `npm install` in the backend directory 3. **Database created**: Ensure your MySQL/PostgreSQL database exists ## Running the Seed Script ### Method 1: Direct Node Execution ```bash cd backend node seeds/seedData.js ``` ### Method 2: Using npm script (if added to package.json) Add this to your `backend/package.json` scripts section: ```json "scripts": { "seed": "node seeds/seedData.js" } ``` Then run: ```bash npm run seed ``` ## What Gets Seeded The seed script will create sample data for all models: ### 1. **Users** (5 users) - Admin user (john.doe@example.com) - Regular users - Staff user - Password for all: `Password123!` ### 2. **Product Categories** (10 categories) - Electronics, Computers, Smartphones, etc. ### 3. **Payment Methods** (6 methods) - Credit Card, PayPal, Bank Transfer, Cash on Delivery, Apple Pay, Google Pay ### 4. **Products** (10 products) - iPhone 15 Pro Max - MacBook Pro - Samsung Galaxy S24 Ultra - Sony Headphones - And more... ### 5. **Orders** (4 orders) - Sample orders with different statuses (delivered, shipped, processing, pending) ### 6. **Order Items** (4 items) - Products associated with orders ### 7. **Product Reviews** (5 reviews) - Customer reviews with ratings and comments ### 8. **Career Positions** (5 positions) - Full Stack Developer, Product Manager, UX Designer, etc. ### 9. **Career Applications** (3 applications) - Sample job applications ### 10. **Newsletter Subscribers** (4 subscribers) - Active and inactive subscribers ### 11. **User Activity Logs** (4 logs) - Login, purchase, review activities ### 12. **Audit Logs** (3 logs) - System audit trail ## Important Notes ⚠️ **WARNING**: The seed script uses `db.sync({ force: true })` which will: - **DROP all existing tables** - **DELETE all existing data** - Recreate all tables from scratch ### For Production If you want to add seed data without deleting existing data: 1. Open `seeds/seedData.js` 2. Change line: ```javascript await db.sync({ force: true }); ``` To: ```javascript // await db.sync({ force: true }); // Comment this out ``` ## Test Credentials After seeding, you can login with: **Admin Account:** - Email: john.doe@example.com - Password: Password123! **User Accounts:** - jane.smith@example.com / Password123! - michael.j@example.com / Password123! - sarah.w@example.com / Password123! - david.b@example.com / Password123! ## Customizing Seed Data To customize the seed data: 1. Open `seeds/seedData.js` 2. Modify the data in the `bulkCreate()` calls 3. Add or remove items as needed 4. Save and run the script again ## Troubleshooting ### Database Connection Error - Check your `.env` file for correct database credentials - Ensure the database server is running - Verify the database exists ### Foreign Key Constraint Errors - Make sure all model associations are properly defined - Check that the order of seeding respects foreign key dependencies ### Module Not Found Errors - Run `npm install` to ensure all dependencies are installed - Check that all model files exist and are properly exported ## Next Steps After seeding: 1. Start your backend server: `npm start` or `node app.js` 2. Start your frontend: `cd .. && npm run dev` 3. Login with one of the test accounts 4. Browse products, place orders, and test features ## Support If you encounter any issues, check: - Database connection settings - Model definitions - Console error messages