# Fix user_id Type Inconsistency Plan

## Problem
`supabase/rep-performance-schema.sql` defines `user_id` as `TEXT` but:
1. All other tables use `UUID` for user_id
2. The tables don't exist in production yet (migration never applied)

## Solution
**Fix the schema file FIRST, then apply it.** No need for a separate type conversion migration.

## Changes Required

### File: `supabase/rep-performance-schema.sql`

**Line 11:** Change from:
```sql
user_id TEXT NOT NULL,
```
To:
```sql
user_id UUID NOT NULL,
```

**Line 82:** Change from:
```sql
user_id TEXT NOT NULL,
```
To:
```sql
user_id UUID NOT NULL,
```

## Implementation Steps
- [ ] Phase 1: Builder updates `rep-performance-schema.sql` (TEXT → UUID on lines 11 and 82)
- [ ] Phase 2: Builder commits and pushes the fix
- [ ] Phase 3: QA applies the corrected migration to Supabase
- [ ] Phase 4: Mark `fix-user-id-type-migration.sql` as OBSOLETE (no longer needed)
- [ ] Phase 5: Update PENDING_MIGRATIONS.md

## Database Migration

After Builder fixes the schema, QA runs the corrected `rep-performance-schema.sql` in Supabase SQL Editor.

## API Endpoints
None changed - code already passes UUIDs as strings.

## UI Components
None changed.

## Success Criteria
1. Tables `rep_weekly_snapshots` and `call_quality_scores` exist in production
2. Both have `user_id` column type = `uuid`
3. Rep performance features work (`/api/jobs/generate-rep-reports`)

## Notes for Builder

### Quick Fix
Just 2 lines to change in `supabase/rep-performance-schema.sql`:
- Line 11: `user_id TEXT NOT NULL` → `user_id UUID NOT NULL`
- Line 82: `user_id TEXT NOT NULL` → `user_id UUID NOT NULL`

### After Fixing
1. Commit with message: "Fix user_id type in rep-performance-schema (TEXT → UUID)"
2. Push to main

## Notes for QA

### After Builder Pushes
1. Pull latest from main
2. Run `supabase/rep-performance-schema.sql` in Supabase SQL Editor
3. Verify tables created with correct type:
```sql
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name IN ('rep_weekly_snapshots', 'call_quality_scores')
AND column_name = 'user_id';
```
Should return `uuid` for both.

4. Update PENDING_MIGRATIONS.md:
   - Mark `fix-user-id-type-migration.sql` as ❌ OBSOLETE
   - Add new entry for `rep-performance-schema.sql` as ✅ Applied

## Obsolete Migration
`supabase/fix-user-id-type-migration.sql` is no longer needed since we're fixing at source. It can be deleted or marked obsolete.

## Why This Approach
- Simpler than applying broken schema then fixing
- No data to migrate (tables don't exist)
- One step instead of two
- Clean schema from the start
