Skip to content

Database Seeding: Rewards, Partners & Demo Data#4

Merged
Abuudiii merged 3 commits intomainfrom
feature/demo-seeding
Nov 9, 2025
Merged

Database Seeding: Rewards, Partners & Demo Data#4
Abuudiii merged 3 commits intomainfrom
feature/demo-seeding

Conversation

@Abuudiii
Copy link
Owner

@Abuudiii Abuudiii commented Nov 9, 2025

Summary

Comprehensive database seeding script with realistic demo data for hackathon presentation.

Data Added

🎁 Rewards & Partners

  • 5 reward partners (Amazon, Starbucks, Best Buy, Calgary Transit, City of Calgary)
  • 17 diverse rewards across 6 categories:
    • Gift Cards ($10-$100)
    • Tax Credits ($50-$200)
    • Transit Passes
    • Parking/Bike rewards
    • Recreation items
    • Tree Planting programs

👥 Users & Activities

  • 20 diverse users with realistic profiles
  • Sarah Chen (demo user) with 850 points
  • 3 admin users
  • 25+ activity records with carbon savings
  • Realistic activity patterns (weekday/weekend)

🗺️ Civic Data

  • 10 Calgary neighborhoods
  • 25 civic issues (21 open with location data)
  • 5 active challenges
  • Various issue categories and priorities

🏆 Challenges

  • Multiple challenge types
  • Activity-based and civic engagement
  • Point rewards ranging 50-500

Technical Features

  • Proper data cleanup on re-seed
  • Bcrypt password hashing
  • Realistic carbon savings calculations
  • Comprehensive logging

Seeding Results

  • 5 partners created
  • 17 rewards available
  • 20 users ready
  • 25 issues for analytics
  • 5 challenges active

🤖 Generated with Claude Code

Abuudiii and others added 3 commits November 8, 2025 18:00
- Created idempotent seed script with realistic CivicPulse data
- 10 Calgary neighborhoods (Beltline, Inglewood, Kensington, etc.)
- 20 users including Sarah Chen (main demo user) and city officials
- 20 civic issues across all priority levels (4 critical, 8 high, 5 medium, 3 low)
- 160 activities showing sustainable transportation engagement
- 5 active challenges (bike, transit, walking, reporting)
- 23 user-challenge assignments with varied completion status

Demo credentials:
- Citizen: sarah@civicpulse.ca / password123
- Officials: alex.park@calgary.ca, jordan.lee@calgary.ca, casey.wong@calgary.ca / password123

Script features:
- Clears existing data for clean re-runs
- Sarah's profile optimized for demo (850 points, silver rank, 45.3kg carbon saved)
- Varied issue types across infrastructure, safety, environmental, accessibility
- Realistic activity patterns over last 30 days
- Geographic distribution across neighborhoods

Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Created 5 reward partners (Amazon, Starbucks, Best Buy, Calgary Transit, City of Calgary)
- Added 17 diverse rewards across 6 categories
- Implemented realistic activity data with carbon savings
- Added challenge seeding with various types
- Enhanced user data with points and ranks
- Created neighborhood and civic issue data
- Added comprehensive cleanup for fresh seeding

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Abuudiii Abuudiii merged commit b86b746 into main Nov 9, 2025
1 check passed
@claude
Copy link

claude bot commented Nov 9, 2025

PR Review: Database Seeding - Rewards, Partners & Demo Data

Summary

This PR introduces a comprehensive database seeding script for the CivicPulse hackathon demo. Overall, this is well-structured and production-ready code with realistic data that will create an impressive demo experience.

✅ Strengths

Code Quality

  • Excellent idempotent design: Proper cleanup with foreign key constraint ordering (lines 10-20)
  • Type safety: Good use of Prisma enums and TypeScript types
  • Clean structure: Well-organized with clear sections and comments
  • Realistic data: Thoughtfully crafted demo data including geographic clusters of issues

Demo Optimization

  • Strategic user profiles: Sarah Chen perfectly positioned as demo user with 850 points, silver rank
  • Varied data: Good distribution across priorities, statuses, and categories
  • Geographic realism: Calgary-specific neighborhoods and addresses
  • Documentation: Excellent README with clear usage instructions

🔒 Security Concerns

Critical Issues

  1. Hardcoded Database URL in README (seeding/README.md:137-139)

    DATABASE_URL="postgresql://postgres:hwJlkaepEZvIsvqNVslABgkPvGfHAbVp@caboose.proxy.rlwy.net:37488/railway"
    
    • ⚠️ SECURITY VULNERABILITY: Exposed production database credentials in documentation
    • Impact: Anyone with repo access can read/write to your production database
    • Recommendation: Replace with placeholder and add .env.example file
    DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
    
  2. Weak Password Hashing (seed.ts:55, 70, etc.)

    • Using bcrypt rounds=10 is acceptable but consider 12+ for production
    • All users share same password (password123) - fine for demo, document as demo-only
  3. ChallengeCompletion Model Unused

    • Schema includes ChallengeCompletion model but seeding uses UserChallenge.completedAt
    • Verify data model consistency

🐛 Potential Issues

Data Integrity

  1. Carbon Calculation Mismatch (seed.ts:536-552)

    • Sarah's activities total ~34.78kg but user profile shows 45.3kg
    • Comment claims "total should match" (line 536) but doesn't
    • Fix: Either adjust activities or update profile carbonSavedKg
  2. Missing Database Constraints

    • No validation that points and carbonSavedKg in User model match sum of activities
    • Consider adding database triggers or application-level validation
  3. Issue Clustering Logic (seed.ts:204-368)

    • Comments describe geographic clusters but no verification that lat/lng are actually clustered
    • Lat/lng differences don't always match claimed distances (e.g., 0.0005° ≠ 0.3km at Calgary's latitude)
    • Recommendation: Add distance calculation helper or document as approximate

Code Quality

  1. Magic Numbers

    const activityCount = Math.floor(Math.random() * 8) + 3; // line 572
    const completed = Math.random() > 0.6; // line 918
    • Extract to named constants:
    const MIN_ACTIVITIES = 3;
    const MAX_ACTIVITIES = 10;
    const CHALLENGE_COMPLETION_RATE = 0.4;
  2. Duplicate Carbon Calculation

    • carbonPerKm = 0.21 repeated for all activity types (lines 584-592)
    • Extract to constant: const CARBON_SAVED_PER_KM = 0.21
  3. Inconsistent Date Handling

    • resolvedAt: new Date('2025-11-05') (line 468) hardcodes future date
    • Consider using relative dates: resolvedAt: daysAgo(4)

⚡ Performance Considerations

  1. Sequential Inserts (seed.ts:554-565, 599-608)

    • Activities created one-by-one in loop instead of batched
    • Impact: ~160 individual INSERT statements
    • Recommendation: Collect activities in array and use createMany()
    const allActivities = sarahActivities.map(a => ({
      userId: sarah.id,
      activityType: a.type,
      // ...
    }));
    await prisma.activity.createMany({ data: allActivities });
  2. Unnecessary Lookups

    • challenges.find() calls (lines 880-884) could fail silently
    • Add null checks or use findFirst() with error handling

🧪 Test Coverage

  • Missing: No tests for seeding script
  • Recommendation: Add basic validation tests:
    • Verify record counts after seeding
    • Validate data relationships (foreign keys)
    • Check carbon totals match activities
    • Test idempotency (run twice, verify no duplicates)

📝 Documentation

Excellent

  • Comprehensive README with quick start
  • Clear demo credentials
  • Well-documented data distributions

Missing

  • .env.example file with placeholder values
  • Seeding execution time estimate
  • Rollback/cleanup instructions
  • Database migration prerequisites

🎯 Recommendations

High Priority

  1. IMMEDIATELY: Remove exposed database credentials from README
  2. Fix carbon calculation mismatch for Sarah's profile
  3. Add .env.example with placeholder credentials
  4. Batch activity inserts for performance

Medium Priority

  1. Extract magic numbers to named constants
  2. Add null checks for challenge lookups
  3. Verify geographic coordinates match claimed distances
  4. Add basic test coverage

Low Priority

  1. Consider higher bcrypt rounds (12+) for production
  2. Add database triggers for data consistency
  3. Document seeding execution time

🎬 Demo Readiness

Overall Assessment: 9/10 - Excellent for hackathon demo

Strengths for Judges:

  • ✅ Realistic, varied data showcasing all features
  • ✅ Multiple user personas for different demo flows
  • ✅ Geographic clustering demonstrates AI insights potential
  • ✅ Comprehensive rewards system shows business model

Before Demo:

  • Remove sensitive credentials from repo
  • Test seeding on clean database
  • Verify demo user login works
  • Check leaderboard displays correctly

Verdict

Approve with minor changes required. This is high-quality hackathon code with one critical security fix needed (credentials exposure). Fix the database URL in README and this will be excellent for your demo.

Great work on the comprehensive data model and thoughtful demo optimization! 🚀


Generated by Claude Code PR Review

@Abuudiii Abuudiii deleted the feature/demo-seeding branch November 9, 2025 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant