Spaces:
Paused

File size: 1,248 Bytes
630aa02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import asyncio
import os
import sys

# Add current directory to path for imports
sys.path.append(os.getcwd())

from core.database import async_session_factory
from sqlalchemy import text

async def debug_db():
    async with async_session_factory() as db:
        # 1. Total counts
        t_res = await db.execute(text("SELECT count(*) FROM tickets WHERE deleted_at IS NULL"))
        u_res = await db.execute(text("SELECT count(*) FROM users"))
        print(f"Total Active Tickets: {t_res.scalar()}")
        print(f"Total Users: {u_res.scalar()}")
        
        # 2. Check a few tickets and their creators' roles
        query = text("""
            SELECT t.title, t.workspace_id, t.created_by, u.email, u.role 
            FROM tickets t
            LEFT JOIN users u ON t.created_by = u.id
            WHERE t.deleted_at IS NULL
            LIMIT 10
        """)
        res = await db.execute(query)
        print("\nSample Tickets & Creator Roles:")
        for row in res.all():
            print(f"  Title: {row[0]}")
            print(f"  WS: {row[1]}")
            print(f"  Creator Email: {row[3]}")
            print(f"  Creator Role: {row[4]}")
            print("-" * 20)

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