from sqlalchemy import create_engine, text from sqlalchemy.orm import sessionmaker from customer_intelligence.config import settings _url = settings.sqlalchemy_database_url _is_sqlite = _url.startswith("sqlite") engine = create_engine( _url, **({ "connect_args": {"check_same_thread": False}, } if _is_sqlite else { "pool_size": 5, "max_overflow": 10, "pool_pre_ping": True, }) ) SessionLocal = sessionmaker(bind=engine, autocommit=False, autoflush=False) def get_engine(): return engine def test_connection() -> bool: try: with engine.connect() as conn: conn.execute(text("SELECT 1")) return True except Exception as e: print(f"DB connection failed: {e}") return False