operations-granite/HuggingFace-Granite-AI-Practice-Agent-Dev
0
1#!/usr/bin/env python32"""3Test database structure and data4"""5 6import sys7import os8sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))9 10import asyncio11from database.db_manager import DatabaseManager12 13async def main():14 print("🔍 Checking CockroachDB Structure\n")15 16 db = DatabaseManager()17 18 async with db.get_connection() as conn:19 # Check tables20 print("=" * 60)21 print("Tables in database:")22 print("=" * 60)23 24 tables = await conn.fetch("""25 SELECT table_name26 FROM information_schema.tables27 WHERE table_schema = 'public'28 ORDER BY table_name29 """)30 31 for table in tables:32 table_name = table['table_name']33 count = await conn.fetchval(f"SELECT COUNT(*) FROM {table_name}")34 print(f" ✅ {table_name}: {count} rows")35 36 # Check meetings table structure37 print("\n" + "=" * 60)38 print("Meetings table columns:")39 print("=" * 60)40 41 try:42 columns = await conn.fetch("""43 SELECT column_name, data_type, is_nullable44 FROM information_schema.columns45 WHERE table_name = 'meetings'46 ORDER BY ordinal_position47 """)48 49 for col in columns:50 nullable = "NULL" if col['is_nullable'] == 'YES' else "NOT NULL"51 print(f" {col['column_name']}: {col['data_type']} ({nullable})")52 except Exception as e:53 print(f" ⚠️ Meetings table doesn't exist or error: {e}")54 55 # Check for users56 print("\n" + "=" * 60)57 print("Users in database:")58 print("=" * 60)59 60 try:61 users = await conn.fetch("""62 SELECT user_id, username, email, fathom_api_key IS NOT NULL as has_fathom63 FROM rfp_users64 LIMIT 565 """)66 67 for user in users:68 fathom = "✅" if user['has_fathom'] else "❌"69 print(f" {fathom} {user['username']} ({user['email']}) - ID: {user['user_id']}")70 except Exception as e:71 print(f" ⚠️ rfp_users table error: {e}")72 73 # Check for meetings74 print("\n" + "=" * 60)75 print("Sample meetings:")76 print("=" * 60)77 78 try:79 meetings = await conn.fetch("""80 SELECT meeting_id, title, created_by, user_id81 FROM meetings82 ORDER BY created_at DESC83 LIMIT 384 """)85 86 if meetings:87 for mtg in meetings:88 print(f" Meeting: {mtg['title'][:50]}")89 print(f" Created by: {mtg.get('created_by', 'NULL')}")90 print(f" User ID: {mtg.get('user_id', 'NULL')}")91 else:92 print(" No meetings found")93 except Exception as e:94 print(f" ⚠️ Meetings query error: {e}")95 import traceback96 traceback.print_exc()97 98if __name__ == "__main__":99 asyncio.run(main())100 