···1+# Deployment Guide - Applying Code Changes to VPS
2+3+When you make code changes to Python files, you need to rebuild the Docker images on your VPS for the changes to take effect.
4+5+## Quick Deploy Commands
6+7+### For Python Firehose/Worker Changes
8+9+If you modified files in `python-firehose/` directory:
10+11+```bash
12+# SSH into your VPS
13+ssh user@your-vps
14+15+# Navigate to the project directory
16+cd /path/to/PublicAppView
17+18+# Pull latest code from git
19+git pull
20+21+# Rebuild and restart the affected service
22+docker-compose build python-backfill-worker
23+docker-compose up -d python-backfill-worker
24+25+# Watch logs to verify the fix
26+docker-compose logs -f python-backfill-worker
27+```
28+29+### For App (Node.js) Changes
30+31+If you modified TypeScript/JavaScript files:
32+33+```bash
34+# Rebuild and restart app service
35+docker-compose build app
36+docker-compose up -d app
37+38+# Watch logs
39+docker-compose logs -f app
40+```
41+42+### Rebuild Everything
43+44+If you're not sure which services changed:
45+46+```bash
47+# Pull latest code
48+git pull
49+50+# Rebuild all services
51+docker-compose build
52+53+# Restart all services
54+docker-compose up -d
55+56+# Watch all logs
57+docker-compose logs -f
58+```
59+60+## Verifying the SQL Fix
61+62+After deploying the `unified_worker.py` fix:
63+64+1. **Rebuild the service:**
65+ ```bash
66+ docker-compose build python-backfill-worker
67+ docker-compose up -d python-backfill-worker
68+ ```
69+70+2. **Watch for errors:**
71+ ```bash
72+ docker-compose logs -f python-backfill-worker | grep -i "error\|syntax"
73+ ```
74+75+3. **Verify database logs:**
76+ ```bash
77+ docker-compose logs -f db | grep -i "syntax error"
78+ ```
79+80+4. **Success indicators:**
81+ - No more `$NULL` or `$false` syntax errors
82+ - Viewer states (likes/reposts) inserting successfully
83+ - No "current transaction is aborted" errors
84+85+## Deployment Checklist
86+87+- [ ] Code changes committed to git
88+- [ ] Pushed to remote repository
89+- [ ] SSH'd into VPS
90+- [ ] Pulled latest code with `git pull`
91+- [ ] Rebuilt Docker images with `docker-compose build`
92+- [ ] Restarted services with `docker-compose up -d`
93+- [ ] Checked logs for errors
94+- [ ] Verified application is working
95+96+## Common Issues
97+98+### "Image is up to date" but code not updated
99+```bash
100+# Force rebuild without cache
101+docker-compose build --no-cache python-backfill-worker
102+docker-compose up -d python-backfill-worker
103+```
104+105+### Container won't stop
106+```bash
107+# Force stop and remove
108+docker-compose stop python-backfill-worker
109+docker-compose rm -f python-backfill-worker
110+docker-compose up -d python-backfill-worker
111+```
112+113+### Database connection errors after restart
114+```bash
115+# Wait for database to be healthy
116+docker-compose ps
117+118+# Check database logs
119+docker-compose logs db
120+121+# Restart dependent services
122+docker-compose restart python-backfill-worker
123+```
124+125+### Out of disk space
126+```bash
127+# Clean up old Docker images
128+docker system prune -a
129+130+# Clean up old containers
131+docker-compose down --volumes
132+docker-compose up -d
133+```
134+135+## Git Workflow
136+137+### Committing Changes
138+139+```bash
140+# On your local machine (in VSCode)
141+git add python-firehose/unified_worker.py
142+git commit -m "Fix: Correct SQL syntax in post_viewer_states INSERT"
143+git push origin main
144+```
145+146+### Deploying to VPS
147+148+```bash
149+# On VPS
150+git pull origin main
151+docker-compose build python-backfill-worker
152+docker-compose up -d python-backfill-worker
153+```
154+155+## Rollback
156+157+If something goes wrong:
158+159+```bash
160+# Revert to previous git commit
161+git log # Find the commit hash you want to revert to
162+git checkout <commit-hash>
163+164+# Rebuild with old code
165+docker-compose build
166+docker-compose up -d
167+168+# Or reset to latest stable
169+git checkout main
170+git pull
171+docker-compose build
172+docker-compose up -d
173+```
174+175+## Health Checks
176+177+Verify services are healthy:
178+179+```bash
180+# Check status
181+docker-compose ps
182+183+# All services should show "healthy" or "running"
184+```
185+186+## Performance Monitoring
187+188+Watch resource usage:
189+190+```bash
191+# Monitor container stats
192+docker stats
193+194+# Watch specific service
195+docker stats python-backfill-worker
196+```
···1+#!/usr/bin/env python3
2+"""
3+Verification script - run this inside the Docker container to check if the fix is applied
4+Usage: docker-compose exec python-backfill-worker python verify_code.py
5+"""
6+7+import inspect
8+import importlib.util
9+10+def check_code():
11+ """Check if the fixed code is present"""
12+ print("="*60)
13+ print("CODE VERIFICATION SCRIPT")
14+ print("="*60)
15+16+ # Load the module
17+ spec = importlib.util.spec_from_file_location("unified_worker", "/app/unified_worker.py")
18+ module = importlib.util.module_from_spec(spec)
19+20+ try:
21+ spec.loader.exec_module(module)
22+ print("\n✓ Module loaded successfully")
23+ except Exception as e:
24+ print(f"\n✗ Failed to load module: {e}")
25+ return
26+27+ # Get the source code of create_post_viewer_state
28+ try:
29+ source = inspect.getsource(module.UnifiedWorker.create_post_viewer_state)
30+ print("\n" + "="*60)
31+ print("SOURCE CODE OF create_post_viewer_state:")
32+ print("="*60)
33+ print(source[:1000]) # Print first 1000 chars
34+35+ # Check for the problematic patterns
36+ if "$NULL" in source or "$false" in source or ".replace" in source:
37+ print("\n❌ OLD CODE DETECTED!")
38+ print("The container is running the OLD buggy code.")
39+ print("Found problematic patterns:")
40+ if "$NULL" in source:
41+ print(" - Found '$NULL'")
42+ if "$false" in source:
43+ print(" - Found '$false'")
44+ if ".replace" in source:
45+ print(" - Found '.replace'")
46+ elif "{like_param}" in source and "{repost_param}" in source:
47+ print("\n✅ NEW CODE DETECTED!")
48+ print("The container is running the FIXED code.")
49+ else:
50+ print("\n⚠ UNKNOWN CODE VERSION")
51+ print("Cannot determine if this is the old or new code.")
52+53+ except Exception as e:
54+ print(f"\n✗ Failed to get source: {e}")
55+56+if __name__ == '__main__':
57+ check_code()