File size: 1,979 Bytes
d4bef91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from sqlalchemy import create_engine, text
from datetime import datetime

DATABASE_URL = "REMOVED_SECRET"

print("="*50)
print("Database Connection Test (No AI)")
print("="*50)

try:
    print("\n[1] Creating engine with 10s timeout...")
    engine = create_engine(DATABASE_URL, connect_args={'connect_timeout': 10})

    print("[2] Attempting connection...")
    with engine.connect() as conn:
        # Test basic connectivity
        result = conn.execute(text("SELECT 1"))
        print("[3] SELECT 1 = OK")

        # Check what tables exist
        tables = conn.execute(text(
            "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"
        )).fetchall()
        print(f"\n--- Tables in database ---")
        for t in tables:
            print(f"  - {t[0]}")

        # Count rows in each table
        for t in tables:
            count = conn.execute(text(f"SELECT COUNT(*) FROM {t[0]}")).scalar()
            print(f"    {t[0]}: {count} rows")

        # Show last 5 analyses
        try:
            rows = conn.execute(text(
                "SELECT id, primary_condition, created_at FROM analyses ORDER BY created_at DESC LIMIT 5"
            )).fetchall()
            print(f"\n--- Last 5 Analyses ---")
            for r in rows:
                print(f"  ID={r[0]}  condition={r[1]}  date={r[2]}")
        except Exception:
            print("  (analyses table not found or empty)")

        # Show users
        try:
            users = conn.execute(text("SELECT id, email, created_at FROM users")).fetchall()
            print(f"\n--- Users ---")
            for u in users:
                print(f"  ID={u[0]}  email={u[1]}  created={u[2]}")
        except Exception:
            print("  (users table not found or empty)")

    print("\n" + "="*50)
    print("CONNECTION SUCCESSFUL")
    print("="*50)

except Exception as e:
    print(f"\nCONNECTION FAILED: {e}")