7.5 KiB
7.5 KiB
Database Seeding
This document describes the demo data seeded into the database for development and testing purposes.
Overview
The database includes 4 seeders that populate initial data:
- Categories Seeder - 7 technical topic categories
- Admin User Seeder - 1 admin account for management
- Questions Seeder - 35 demo questions (5 per category)
- Achievements Seeder - 19 gamification achievements
Running Seeders
Seed all data
npm run seed
# or
npx sequelize-cli db:seed:all
Undo all seeders
npm run seed:undo
# or
npx sequelize-cli db:seed:undo:all
Reseed (undo + seed)
npm run seed:undo && npm run seed
Seeded Data Details
1. Categories (7 total)
| Category | Slug | Guest Accessible | Display Order | Icon |
|---|---|---|---|---|
| JavaScript | javascript |
✅ Yes | 1 | 🟨 |
| Angular | angular |
✅ Yes | 2 | 🅰️ |
| React | react |
✅ Yes | 3 | ⚛️ |
| Node.js | nodejs |
❌ Auth Required | 4 | 🟢 |
| TypeScript | typescript |
❌ Auth Required | 5 | 📘 |
| SQL & Databases | sql-databases |
❌ Auth Required | 6 | 🗄️ |
| System Design | system-design |
❌ Auth Required | 7 | 🏗️ |
Guest vs. Auth:
- Guest-accessible (3): JavaScript, Angular, React - Users can take quizzes without authentication
- Auth-required (4): Node.js, TypeScript, SQL & Databases, System Design - Must be logged in
2. Admin User (1 total)
Credentials:
- Email:
admin@quiz.com - Password:
Admin@123 - Username:
admin - Role:
admin
Use Cases:
- Test admin authentication
- Create/edit questions
- Manage categories
- View analytics
- Test admin-only features
3. Questions (35 total)
Distribution by Category:
- JavaScript: 5 questions
- Angular: 5 questions
- React: 5 questions
- Node.js: 5 questions
- TypeScript: 5 questions
- SQL & Databases: 5 questions
- System Design: 5 questions
By Difficulty:
- Easy: 15 questions (5 points, 60 seconds)
- Medium: 15 questions (10 points, 90 seconds)
- Hard: 5 questions (15 points, 120 seconds)
Question Types:
- Multiple Choice: All 35 questions
- True/False: 0 questions (can be added later)
- Written: 0 questions (can be added later)
Sample Questions:
JavaScript:
- What is the difference between let and var? (Easy)
- What is a closure in JavaScript? (Medium)
- What does the spread operator (...) do? (Easy)
- What is the purpose of Promise.all()? (Medium)
- What is event delegation? (Medium)
Angular:
- What is the purpose of NgModule? (Easy)
- What is dependency injection? (Medium)
- What is the difference between @Input() and @Output()? (Easy)
- What is RxJS used for? (Medium)
- What is the purpose of Angular lifecycle hooks? (Easy)
React:
- What is the virtual DOM? (Easy)
- What is the purpose of useEffect hook? (Easy)
- What is prop drilling? (Medium)
- What is the difference between useMemo and useCallback? (Medium)
- What is React Context API used for? (Easy)
Node.js:
- What is the event loop? (Medium)
- What is middleware in Express.js? (Easy)
- What is the purpose of package.json? (Easy)
- What is the difference between process.nextTick() and setImmediate()? (Hard)
- What is clustering in Node.js? (Medium)
TypeScript:
- What is the difference between interface and type? (Medium)
- What is a generic? (Medium)
- What is the "never" type? (Hard)
- What is type narrowing? (Medium)
- What is the purpose of the "readonly" modifier? (Easy)
SQL & Databases:
- What is the difference between INNER JOIN and LEFT JOIN? (Easy)
- What is database normalization? (Medium)
- What is an index in a database? (Easy)
- What is a transaction in SQL? (Medium)
- What does the GROUP BY clause do? (Easy)
System Design:
- What is horizontal scaling vs vertical scaling? (Easy)
- What is a load balancer? (Easy)
- What is CAP theorem? (Medium)
- What is caching and why is it used? (Easy)
- What is a microservices architecture? (Medium)
4. Achievements (19 total)
By Category:
Milestone (4):
- 🎯 First Steps - Complete your very first quiz (10 pts)
- 📚 Quiz Enthusiast - Complete 10 quizzes (50 pts)
- 🏆 Quiz Master - Complete 50 quizzes (250 pts)
- 👑 Quiz Legend - Complete 100 quizzes (500 pts)
Score (3):
- 💯 Perfect Score - Achieve 100% on any quiz (100 pts)
- ⭐ Perfectionist - Achieve 100% on 5 quizzes (300 pts)
- 🎓 High Achiever - Maintain 80% average across all quizzes (200 pts)
Speed (2):
- ⚡ Speed Demon - Complete a quiz in under 2 minutes (75 pts)
- 🚀 Lightning Fast - Complete 10 quizzes in under 2 minutes each (200 pts)
Streak (3):
- 🔥 On a Roll - Maintain a 3-day streak (50 pts)
- 🔥🔥 Week Warrior - Maintain a 7-day streak (150 pts)
- 🔥🔥🔥 Month Champion - Maintain a 30-day streak (500 pts)
Quiz (3):
- 🗺️ Explorer - Complete quizzes in 3 different categories (100 pts)
- 🌟 Jack of All Trades - Complete quizzes in 5 different categories (200 pts)
- 🌈 Master of All - Complete quizzes in all 7 categories (400 pts)
Special (4):
- 🌅 Early Bird - Complete a quiz before 8 AM (50 pts)
- 🦉 Night Owl - Complete a quiz after 10 PM (50 pts)
- 🎉 Weekend Warrior - Complete 10 quizzes on weekends (100 pts)
- 💪 Comeback King - Score 90%+ after scoring below 50% (150 pts)
Achievement Requirements:
Achievement unlocking is tracked via the requirement_type field:
quizzes_completed- Based on total quizzes completedquizzes_passed- Based on quizzes passed (e.g., 80% average)perfect_score- Based on number of 100% scoresstreak_days- Based on consecutive days streakcategory_master- Based on number of different categories completedspeed_demon- Based on quiz completion timeearly_bird- Based on time of day (also used for Night Owl, Weekend Warrior, Comeback King)
Verification
To verify seeded data, run:
node verify-seeded-data.js
This will output:
- Row counts for each table
- List of all categories
- Admin user credentials
- Questions count by category
- Achievements count by category
Data Integrity
All seeded data maintains proper relationships:
-
Questions → Categories
- Each question has a valid
category_idforeign key - Category slugs are used to find category IDs during seeding
- Each question has a valid
-
Questions → Users
- All questions have
created_byset to admin user ID - Admin user is seeded before questions
- All questions have
-
Categories
- Each has a unique slug for URL routing
- Display order ensures consistent sorting
-
Achievements
- All have valid category ENUM values
- All have valid requirement_type ENUM values
Notes
- All timestamps are set to the same time during seeding for consistency
- All UUIDs are regenerated on each seed run
- Guest-accessible categories allow unauthenticated quiz taking
- Auth-required categories need user authentication
- Questions include explanations for learning purposes
- All questions are multiple-choice with 4 options
- Correct answers are stored as JSON arrays (supports multiple correct answers)
Future Enhancements
Consider adding:
- More questions per category (currently 5)
- True/False question types
- Written answer question types
- Guest settings seeder
- Sample user accounts (non-admin)
- Quiz session history
- User achievement completions