Files
TurboTrades/SEEDING.md
2026-01-10 04:57:43 +00:00

291 lines
6.0 KiB
Markdown

# Database Seeding Guide
## 🌱 Quick Start
To populate your database with sample marketplace items:
```bash
# Make sure MongoDB is running
mongod
# In another terminal, navigate to project root
cd TurboTrades
# Run the seed script
npm run seed
```
That's it! Your database is now populated with sample items.
---
## 📊 What Gets Seeded
### Items Created
- **CS2 Items**: 20+ skins including:
- Legendary rifles (AK-47 | Redline, M4A4 | Howl, AWP | Dragon Lore)
- Premium pistols (Desert Eagle | Blaze, Glock-18 | Fade)
- High-value knives (Karambit | Fade, Butterfly Knife | Doppler)
- Exclusive gloves (Sport Gloves | Pandora's Box)
- Various rarities and price points ($12.99 - $8,999.99)
- **Rust Items**: 4+ skins including:
- AK-47 | Glory
- Python Revolver | Tempered
- MP5 | Tempered
- Metal Facemask | Red Hazmat
### Default Admin User
If no admin user exists, one will be created:
- **Username**: TurboTrades Admin
- **Steam ID**: 76561198000000000
- **Staff Level**: 3 (Admin)
- **Balance**: $100,000
- **Trade URL**: Pre-configured
All items are listed by this admin user.
---
## 🎯 After Seeding
### 1. Start the Backend
```bash
npm run dev
```
### 2. Start the Frontend
```bash
cd frontend
npm run dev
```
### 3. View Items in Browser
Open `http://localhost:5173` and you should see:
- Featured items on homepage
- Full marketplace at `/market`
- Items with images, prices, and details
- Working filters and search
---
## 🔍 Verify Seeding
### Check MongoDB Directly
```bash
# Connect to MongoDB
mongosh
# Use the database
use turbotrades
# Count items
db.items.countDocuments()
# Should return 24+
# View a sample item
db.items.findOne()
# Check featured items
db.items.find({ featured: true }).count()
# Should return 8
# Check by game
db.items.find({ game: 'cs2' }).count()
db.items.find({ game: 'rust' }).count()
```
### Check via API
```bash
# Get all items
curl http://localhost:3000/market/items
# Get featured items
curl http://localhost:3000/market/featured
# Get market stats
curl http://localhost:3000/market/stats
```
---
## 🗑️ Clear Database
To remove all seeded items and start fresh:
### Option 1: Re-run Seed Script
The seed script automatically clears existing items before inserting new ones:
```bash
npm run seed
```
### Option 2: Manual Clear (MongoDB)
```bash
mongosh
use turbotrades
# Delete all items
db.items.deleteMany({})
# Verify
db.items.countDocuments()
```
### Option 3: Drop Entire Database
```bash
mongosh
use turbotrades
# Drop the entire database
db.dropDatabase()
# Then re-seed
exit
npm run seed
```
---
## 🎨 Customize Seed Data
Edit `seed.js` to customize the items:
### Add More Items
```javascript
// In seed.js, add to cs2Items or rustItems array:
{
name: 'Your Item Name',
description: 'Item description',
image: 'https://your-image-url.com/image.jpg',
game: 'cs2', // or 'rust'
category: 'rifles', // rifles, pistols, knives, gloves, etc.
rarity: 'legendary', // common, uncommon, rare, mythical, legendary, ancient, exceedingly
wear: 'fn', // fn, mw, ft, ww, bs (or null for Rust items)
float: 0.01, // 0-1 for CS2, null for Rust
statTrak: false,
price: 99.99,
featured: false,
}
```
### Change Featured Items
Set `featured: true` on items you want to appear on the homepage.
### Adjust Prices
Modify the `price` field for any item.
---
## 🐛 Troubleshooting
### Error: Cannot connect to MongoDB
```
❌ Error: connect ECONNREFUSED 127.0.0.1:27017
```
**Solution**: Start MongoDB first
```bash
mongod
```
### Error: No admin user created
**Solution**: The script creates one automatically. If issues persist:
```bash
mongosh
use turbotrades
db.users.findOne({ staffLevel: { $gte: 3 } })
```
### Items not showing in frontend
1. **Check backend is running**: `http://localhost:3000/health`
2. **Check API returns items**: `http://localhost:3000/market/items`
3. **Check browser console** for errors
4. **Verify MongoDB has data**: `db.items.countDocuments()`
### Images not loading
The seed script uses placeholder Steam CDN URLs. Some may not work. You can:
1. Update image URLs in `seed.js`
2. Use your own hosted images
3. Replace with placeholder services like `https://via.placeholder.com/330x192`
---
## 📝 Seed Script Details
### What It Does
1. Connects to MongoDB
2. Clears existing items (`Item.deleteMany({})`)
3. Finds or creates an admin user
4. Inserts all items with random listing dates
5. Displays summary statistics
6. Disconnects from MongoDB
### Safe to Run Multiple Times
Yes! The script clears old data first, so you can run it anytime to refresh your data.
### Script Location
- **File**: `TurboTrades/seed.js`
- **Model**: `TurboTrades/models/Item.js`
- **Command**: `npm run seed`
---
## 🚀 Production Considerations
### DO NOT Use Seed Data in Production
This seed data is for **development and testing only**.
For production:
1. Remove seed script or restrict access
2. Implement proper item creation via admin interface
3. Use real Steam inventory integration
4. Add proper image hosting/CDN
5. Implement trade bot integration
### Backup Before Seeding
If you have real data:
```bash
# Backup
mongodump --db turbotrades --out ./backup
# Restore if needed
mongorestore --db turbotrades ./backup/turbotrades
```
---
## ✅ Success Checklist
After seeding, verify:
- [ ] Seed script completed without errors
- [ ] MongoDB contains 24+ items
- [ ] Admin user exists in database
- [ ] Backend starts successfully
- [ ] `/market/items` API endpoint returns data
- [ ] Frontend displays items on homepage
- [ ] Featured items show on homepage
- [ ] Market page shows full item list
- [ ] Filters work (game, category, rarity)
- [ ] Search works (try "AK-47" or "Dragon")
- [ ] Item details page loads
---
## 🎉 You're All Set!
Your marketplace now has sample data and is ready to use!
**Next Steps:**
1. Explore the marketplace in your browser
2. Test purchasing (requires Steam login)
3. Try different filters and search
4. Check item detail pages
5. Start building new features!
---
**Created**: January 2025
**Version**: 1.0.0
**Seed Data**: 24+ items, 1 admin user