|
| 1 | +# π How to Run the Feedback Status Migration |
| 2 | + |
| 3 | +## β
Step-by-Step Instructions |
| 4 | + |
| 5 | +### **1. Activate Virtual Environment** |
| 6 | +```bash |
| 7 | +cd /Users/yubraj/Developer/Coding/surmm/aipilot.v2/Backend |
| 8 | + |
| 9 | +# Activate venv |
| 10 | +source venv/bin/activate |
| 11 | +``` |
| 12 | + |
| 13 | +### **2. Install Required Package (tenacity already in requirements.txt)** |
| 14 | +```bash |
| 15 | +# Tenacity is already in your requirements.txt, but make sure it's installed: |
| 16 | +pip install tenacity |
| 17 | +``` |
| 18 | + |
| 19 | +### **3. Run the Migration** |
| 20 | +```bash |
| 21 | +# Run the migration script |
| 22 | +python migrations/add_feedback_status_tracking.py |
| 23 | +``` |
| 24 | + |
| 25 | +### **4. Verify It Worked** |
| 26 | +You should see output like: |
| 27 | +``` |
| 28 | +====================================================================== |
| 29 | +π Adding status tracking to ai_feedback table... |
| 30 | +====================================================================== |
| 31 | +
|
| 32 | +π Step 1: Making feedback_data nullable... |
| 33 | +β
feedback_data is now nullable |
| 34 | +
|
| 35 | +π Step 2: Adding status tracking columns... |
| 36 | +β
All columns added successfully |
| 37 | +
|
| 38 | +π Step 3: Creating index for faster queries... |
| 39 | +β
Index created |
| 40 | +
|
| 41 | +π Step 4: Setting timestamps for existing rows... |
| 42 | +β
Timestamps updated for existing feedback |
| 43 | +
|
| 44 | +====================================================================== |
| 45 | +β
Migration completed successfully! |
| 46 | +====================================================================== |
| 47 | +π XXX existing feedback rows marked as 'completed' (100%) |
| 48 | +``` |
| 49 | + |
| 50 | +### **5. Restart Your Backend** |
| 51 | +```bash |
| 52 | +# Stop your current backend (Ctrl+C if running) |
| 53 | + |
| 54 | +# Start again |
| 55 | +uvicorn main:app --reload |
| 56 | +``` |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +## π Verify in Database (Optional) |
| 61 | + |
| 62 | +```sql |
| 63 | +-- Check new columns exist |
| 64 | +SELECT column_name, data_type, is_nullable |
| 65 | +FROM information_schema.columns |
| 66 | +WHERE table_name = 'ai_feedback' |
| 67 | +AND column_name IN ('generation_status', 'generation_progress', 'error_message'); |
| 68 | + |
| 69 | +-- Check existing feedback |
| 70 | +SELECT |
| 71 | + id, |
| 72 | + generation_status, |
| 73 | + generation_progress, |
| 74 | + completed_at |
| 75 | +FROM ai_feedback |
| 76 | +LIMIT 5; |
| 77 | +``` |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## π If You Need to Rollback |
| 82 | + |
| 83 | +```bash |
| 84 | +python migrations/add_feedback_status_tracking.py down |
| 85 | +``` |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## β οΈ Troubleshooting |
| 90 | + |
| 91 | +### Error: "relation already exists" or "column already exists" |
| 92 | +**Solution:** Migration already ran! You're good to go. |
| 93 | + |
| 94 | +### Error: "column feedback_data must have a default value" |
| 95 | +**Solution:** The migration handles this by making it nullable first. |
| 96 | + |
| 97 | +### Error: "permission denied" |
| 98 | +**Solution:** Make sure your database user has ALTER TABLE permissions. |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## β
What Happens to Existing Data? |
| 103 | + |
| 104 | +- **SAFE:** All existing feedback rows are preserved |
| 105 | +- **SAFE:** All existing `feedback_data` content stays intact |
| 106 | +- **SAFE:** Existing rows marked as `status='completed'`, `progress=100` |
| 107 | +- **SAFE:** Timestamps set to match `generated_at` for existing rows |
| 108 | +- **SAFE:** No data loss - migration only ADDS columns |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## π― Ready to Test! |
| 113 | + |
| 114 | +After migration: |
| 115 | +1. Backend will start using new status tracking automatically |
| 116 | +2. Submit a new answer with `generate_feedback=true` |
| 117 | +3. Poll `/api/feedback/status/answer/{answer_id}` to see progress |
| 118 | +4. Old feedback will still display normally |
| 119 | + |
| 120 | +**All set!** π |
0 commit comments