File size: 1,325 Bytes
363cda9
 
 
 
 
 
 
 
 
 
 
 
 
3370983
363cda9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Test basic database connection.

Run standalone:
>>> POSTGRES_HOST=localhost POSTGRES_PORT=5433 python scripts/db/test_connection.py
"""

import os
from sqlalchemy import text

# Ensure project root is in path
import scripts.db  # noqa: F401

from src.backend.database.candidates.client import get_engine


def test_connection() -> bool:
    """
    Test basic database connectivity.
    
    Returns:
        True if connection successful, False otherwise.
    """
    print("--- Testing Database Connection ---")
    
    # Print environment info
    print(f"POSTGRES_HOST (env): {os.environ.get('POSTGRES_HOST')}")
    print(f"POSTGRES_PORT (env): {os.environ.get('POSTGRES_PORT')}")
    
    try:
        engine = get_engine()
        print(f"Engine URL: {engine.url}")
        
        with engine.connect() as connection:
            print("✅ Connection successful!")
            result = connection.execute(text("SELECT 1"))
            print(f"✅ SELECT 1 result: {result.fetchone()}")
            return True
            
    except Exception as e:
        print("\n❌ Connection FAILED")
        print(f"Error type: {type(e).__name__}")
        print(f"Error message: {str(e)}")
        import traceback
        traceback.print_exc()
        return False


if __name__ == "__main__":
    test_connection()