Spaces:
Paused

miracle / scratch /raw_debug.py
dushyantsingh0
backend stabilization
630aa02
Raw History Blame Contribute Delete
1.25 kB
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())