File size: 1,615 Bytes
c50a873
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import sys
import json
from datetime import date
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# Add app to path
sys.path.insert(0, os.path.abspath('.'))

from app.core.config import settings
from app.models.user import User
from app.models.goal import Goal
from app.models.progress import Progress

def debug_db():
    engine = create_engine(settings.DATABASE_URL)
    SessionLocal = sessionmaker(bind=engine)
    db = SessionLocal()
    
    try:
        user_id = "testuser"
        user = db.query(User).filter(User.user_id == user_id).first()
        if not user:
            print(f"User {user_id} not found")
            return
            
        print(f"--- User: {user.user_id} ---")
        print(f"XP: {user.xp}, Level: {user.level}, Streak: {user.current_streak}")
        
        goals = db.query(Goal).filter(Goal.user_id == user_id).all()
        print(f"\n--- Goals ({len(goals)}) ---")
        for g in goals:
            print(f"ID: {g.id}, Text: {g.goal_text}, Active: {g.is_active}, Completed: {g.is_completed}")
            # print(f"Plan JSON: {g.plan_json[:100]}...")
            
        today = date.today().isoformat()
        print(f"\n--- Progress for Today ({today}) ---")
        progress_today = db.query(Progress).filter(Progress.user_id == user_id, Progress.date == today).all()
        for p in progress_today:
            print(f"ID: {p.id}, GoalID: {p.goal_id}, Topic: {p.topic}, Completed: {p.completed}")
            print(f"Tasks: {p.tasks}")
            
    finally:
        db.close()

if __name__ == "__main__":
    debug_db()