Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions seeding/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.env
222 changes: 222 additions & 0 deletions seeding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
# CivicPulse Database Seeding

Comprehensive database seeding script for CivicPulse demo with realistic Calgary data.

## Quick Start

```bash
cd seeding
npm install
npm run seed
```

## What Gets Created

### Neighborhoods (10)
- Beltline
- Inglewood
- Kensington
- Mission
- Bridgeland
- Ramsay
- Victoria Park
- East Village
- Hillhurst
- Sunnyside

### Users (20)

**Main Demo User:**
- Sarah Chen (sarah@civicpulse.ca)
- Silver rank, 850 points
- 45.3 kg carbon saved
- Lives in Beltline
- Active in challenges and issue reporting

**City Officials (3):**
- Alex Park (alex.park@calgary.ca) - Public Works Department
- Jordan Lee (jordan.lee@calgary.ca) - Parks Department
- Casey Wong (casey.wong@calgary.ca) - Transportation Department

**Citizens (16):**
- Varied ranks: 1 platinum, 3 gold, 3 silver, 9 bronze
- Points range: 200 - 2100
- Distributed across all neighborhoods

**Password for all users:** `password123`

### Issues (20)

**Priority Distribution:**
- Critical: 4 issues (flooding, traffic light out, tree hazard, accessibility blocker)
- High: 8 issues (potholes, streetlights, dumping, infrastructure)
- Medium: 5 issues (park maintenance, signage, graffiti)
- Low: 3 issues (suggestions and improvement requests)

**Key Demo Issue:**
- Sarah's pothole report in Beltline bike lane (high priority, open status)

**Categories:**
- Infrastructure
- Safety
- Environmental
- Accessibility

**Status Distribution:**
- Open: ~15 issues
- In Progress: ~10 issues
- Resolved: ~5 issues

### Activities (160)

**Sarah's Activities (14):**
- Recent sustainable transportation trips
- Mix of biking, walking, and transit
- Total carbon saved aligns with profile (45.3 kg)

**Other Users (146):**
- 3-10 activities per user
- Random distribution over last 30 days
- Varied activity types and distances

### Challenges (5)

1. **Bike to Work Week**
- City issued
- 100 points reward
- Nov 1-8, 2025

2. **Car-Free November**
- City issued
- 200 points reward
- Nov 1-30, 2025

3. **Transit Champion**
- City issued
- 75 points reward
- Nov 4-11, 2025

4. **Walking Warrior**
- AI generated
- 150 points reward
- Nov 1-30, 2025

5. **Community Reporter**
- City issued
- 50 points reward
- Nov 1-15, 2025

### User Challenges (23)

- Sarah joined "Bike to Work Week" (in progress)
- Sarah joined "Community Reporter" (in progress)
- 11 other active users with 1-3 challenges each
- ~40% completion rate across all assignments

## Features

### Idempotent Seeding
- Clears all existing data before seeding
- Can be run multiple times safely
- Respects foreign key constraints

### Realistic Data
- Calgary neighborhood names
- Diverse, realistic user names
- Detailed issue descriptions
- Varied activity patterns
- Appropriate carbon savings calculations

### Demo Optimized
- Sarah's profile perfect for citizen demo
- Mix of issue priorities for dashboard impact
- Active challenges showing engagement
- Recent activity data for leaderboards

## Database Connection

Uses environment variable from `.env`:
```
DATABASE_URL="postgresql://postgres:hwJlkaepEZvIsvqNVslABgkPvGfHAbVp@caboose.proxy.rlwy.net:37488/railway"
```

## Scripts

```bash
# Generate Prisma client
npm run generate

# Run seeding
npm run seed
```

## Output

Successful seeding shows:
```
🧹 Clearing existing data...
βœ… Existing data cleared

🏘️ Creating Calgary neighborhoods...
βœ… Created 10 neighborhoods

πŸ‘₯ Creating users...
✨ Created demo user: Sarah Chen
βœ… Created 3 city officials
βœ… Created 16 citizen users
βœ… Total users created: 20

🎯 Creating challenges...
βœ… Created 5 active challenges

🚨 Creating civic issues...
βœ… Created 20 civic issues
- Critical: 4
- High: 8
- Medium: 5
- Low: 3

🚴 Creating user activities...
βœ… Created 14 activities for Sarah Chen
βœ… Created activities for 19 other users
βœ… Total activities created: 160

πŸ† Assigning users to challenges...
βœ… Created 23 user-challenge assignments

πŸŽ‰ Database seeding complete!
```

## For Demo Purposes

### Citizen Flow Demo (Sarah Chen)
1. Login: sarah@civicpulse.ca / password123
2. Check leaderboard position (silver rank, 850 points)
3. View active challenges (2 in progress)
4. See recent activities (14 sustainable trips)
5. Report new pothole issue (similar to existing one)

### City Dashboard Demo (Alex Park)
1. Login: alex.park@calgary.ca / password123
2. View all issues by priority
3. Filter by department (Public Works)
4. See critical issues requiring immediate attention
5. Review issue details and assign crews

### Leaderboard
Top users for competitive display:
1. Marcus Johnson - 2100 points (platinum)
2. Priya Sharma - 1450 points (gold)
3. Casey Wong - 1200 points (gold)
4. David Kim - 1150 points (gold)
5. Emma Rodriguez - 920 points (silver)
6. Sarah Chen - 850 points (silver) ← Demo user

## Data Integrity

- All users have hashed passwords (bcrypt, 10 rounds)
- Neighborhoods properly linked to users
- Issues linked to users with valid categories/priorities
- Activities linked to users with realistic carbon calculations
- Challenge assignments with proper timestamps
- No orphaned records
Loading