Spaces:
Sleeping

File size: 5,236 Bytes
2026abe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import asyncio
import os
import json
from dotenv import load_dotenv
import asyncpg

load_dotenv(".env")
db_url = os.getenv("DATABASE_URL")

async def main():
    conn = await asyncpg.connect(db_url)
    
    print("=================== 1. ALL TABLES IN SUPABASE ===================")
    tables = await conn.fetch("""
        SELECT table_name 
        FROM information_schema.tables 
        WHERE table_schema = 'public' 
        ORDER BY table_name;
    """)
    for t in tables:
        tname = t["table_name"]
        cnt = await conn.fetchval(f'SELECT COUNT(*) FROM "{tname}"')
        print(f"  • {tname:<25} : {cnt} rows")
    
    print("\n=================== 2. USER PROFILE DATA ===================")
    users = await conn.fetch('SELECT * FROM "users"')
    for u in users:
        u_dict = dict(u)
        print(f"  ID: {u_dict.get('id')}")
        print(f"  Name: {u_dict.get('name')}")
        print(f"  Email: {u_dict.get('email')}")
        print(f"  Course: {u_dict.get('course')}")
        print(f"  Semester: {u_dict.get('semester')}")
        print(f"  University: {u_dict.get('university_name')}")
        print(f"  Onboarding Complete: {u_dict.get('onboarding_complete')}")
        print(f"  Has Syllabus: {u_dict.get('has_syllabus')}")
        print(f"  Gamification: Level {u_dict.get('level')}, XP {u_dict.get('xp_total')}, Coins {u_dict.get('coins')}, Streak {u_dict.get('streak_days')}")
        print(f"  Tokens Consumed: {u_dict.get('tokens_consumed')}")
        print(f"  Total Messages: {u_dict.get('total_messages_sent')}")
        print(f"\n  Preferences:\n{json.dumps(u_dict.get('preferences'), indent=4) if u_dict.get('preferences') else 'None'}")
        print(f"\n  User Facts (Memory/Persona):\n{u_dict.get('user_facts')}")

    print("\n=================== 3. CONVERSATIONS (7) ===================")
    convs = await conn.fetch('SELECT id, title, is_pinned, created_at, updated_at FROM "conversations" ORDER BY created_at ASC')
    for c in convs:
        created_str = c['created_at'].strftime('%Y-%m-%d %H:%M')
        print(f"  • {created_str} | Title: \"{c['title']}\" (ID: {c['id']})")

    print("\n=================== 4. DAILY MEMORIES (2) ===================")
    mems = await conn.fetch('SELECT * FROM "daily_memories"')
    for m in mems:
        m_dict = dict(m)
        print(f"  • Date: {m_dict.get('date')}")
        print(f"    Summary:\n{m_dict.get('summary')}\n")

    print("\n=================== 5. STUDY PLANS (1) ===================")
    plans = await conn.fetch('SELECT id, active, starts_at, ends_at, plan_data FROM "study_plans"')
    for p in plans:
        m_dict = dict(p)
        pd = m_dict.get("plan_data")
        print(f"  • Plan ID: {m_dict.get('id')} | Active: {m_dict.get('active')} | {m_dict.get('starts_at')} to {m_dict.get('ends_at')}")
        if isinstance(pd, str):
            pd = json.loads(pd)
        if isinstance(pd, dict):
            print(f"    Duration Days: {pd.get('duration_days')}")
            print(f"    Days count: {len(pd.get('days', []))}")
            for day in pd.get('days', []):
                print(f"      - Day {day.get('day_number')} ({day.get('date')}): {day.get('focus_area')}")

    print("\n=================== 6. STUDY NOTES (24) ===================")
    notes = await conn.fetch('SELECT id, topic_name, subject_name, bookmarked, created_at, content FROM "study_notes" ORDER BY created_at DESC')
    for n in notes:
        content_preview = n['content'].replace('\n', ' ')[:90]
        print(f"  • [{n['created_at'].strftime('%Y-%m-%d %H:%M')}] Subject: {n['subject_name']} | Topic: {n['topic_name']}")
        print(f"    Preview: {content_preview}...")

    print("\n=================== 7. USER PROGRESS (103 topics) ===================")
    prog_stats = await conn.fetch("""
        SELECT status, COUNT(*) as count 
        FROM user_progress 
        GROUP BY status
    """)
    for ps in prog_stats:
        print(f"  • Status \"{ps['status']}\": {ps['count']} topics")
    
    non_zero = await conn.fetch("SELECT * FROM user_progress WHERE status != 'not_started'")
    print(f"  Topics with active progress: {len(non_zero)}")
    for nz in non_zero:
        d = dict(nz)
        print(f"    - Topic ID: {d.get('topic_id')} | Status: {d.get('status')} | Mastery: {d.get('mastery_score')} | Review: {d.get('next_review_date')}")

    print("\n=================== 8. CHAT MESSAGES SUMMARY (54) ===================")
    msg_count = await conn.fetchval('SELECT COUNT(*) FROM "messages"')
    user_msg_count = await conn.fetchval("SELECT COUNT(*) FROM \"messages\" WHERE role = 'user'")
    ai_msg_count = await conn.fetchval("SELECT COUNT(*) FROM \"messages\" WHERE role = 'assistant'")
    print(f"  Total Messages: {msg_count} (User: {user_msg_count}, AI: {ai_msg_count})")

    last_5 = await conn.fetch('SELECT role, content, created_at FROM "messages" ORDER BY created_at DESC LIMIT 5')
    print("\n  Latest 5 Messages:")
    for m in reversed(last_5):
        preview = m['content'].replace('\n', ' ')[:100]
        print(f"    [{m['role'].upper()}] ({m['created_at'].strftime('%Y-%m-%d %H:%M')}): {preview}...")

    await conn.close()

if __name__ == "__main__":
    asyncio.run(main())