File size: 2,714 Bytes
c024705
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Check database tables and structure
"""

import sqlite3

def check_database_structure():
    """Check database tables and structure"""
    
    DB_FILE = "aimhsa.db"
    
    try:
        conn = sqlite3.connect(DB_FILE)
        
        print("="*60)
        print("DATABASE STRUCTURE CHECK")
        print("="*60)
        
        # Get all tables
        tables = conn.execute("""
            SELECT name FROM sqlite_master WHERE type='table' ORDER BY name
        """).fetchall()
        
        print(f"\nFound {len(tables)} tables:")
        for table in tables:
            print(f"   - {table[0]}")
        
        # Check automated_bookings table structure
        print("\n" + "="*40)
        print("AUTOMATED_BOOKINGS TABLE STRUCTURE:")
        print("="*40)
        columns = conn.execute("PRAGMA table_info(automated_bookings)").fetchall()
        for col in columns:
            print(f"   {col[1]} ({col[2]})")
        
        # Check if there's a user-related table
        print("\n" + "="*40)
        print("CHECKING FOR USER DATA:")
        print("="*40)
        
        # Look for any table that might contain user data
        for table in tables:
            table_name = table[0]
            if 'user' in table_name.lower() or 'account' in table_name.lower():
                print(f"\nTable: {table_name}")
                columns = conn.execute(f"PRAGMA table_info({table_name})").fetchall()
                for col in columns:
                    print(f"   {col[1]} ({col[2]})")
                
                # Check if it has data
                count = conn.execute(f"SELECT COUNT(*) FROM {table_name}").fetchone()[0]
                print(f"   Records: {count}")
                
                if count > 0:
                    sample = conn.execute(f"SELECT * FROM {table_name} LIMIT 3").fetchall()
                    print(f"   Sample data: {sample}")
        
        # Check automated_bookings data
        print("\n" + "="*40)
        print("AUTOMATED_BOOKINGS DATA:")
        print("="*40)
        bookings = conn.execute("""
            SELECT booking_id, user_account, professional_id, risk_level, risk_score
            FROM automated_bookings 
            ORDER BY created_ts DESC
            LIMIT 5
        """).fetchall()
        
        if bookings:
            print(f"Found {len(bookings)} bookings:")
            for b in bookings:
                print(f"   {b[0]} | {b[1]} | {b[2]} | {b[3]} | {b[4]}")
        else:
            print("❌ No bookings found")
        
        conn.close()
        
    except Exception as e:
        print(f"❌ Database Error: {e}")

if __name__ == "__main__":
    check_database_structure()