from sqlmodel import Session, create_engine, text
from app.core.config import settings

def test_conn():
    url = settings.database_url.replace("+asyncpg", "+psycopg2")
    # Try adding .supabase.co if it's missing the dot
    if "ggo08co8sokggcc040o800c4" in url and "supabase.co" not in url:
        url = url.replace("ggo08co8sokggcc040o800c4", "db.ggo08co8sokggcc040o800c4.supabase.co")
    
    print(f"Testing URL: {url}")
    try:
        engine = create_engine(url)
        with Session(engine) as session:
            session.exec(text("SELECT 1"))
        print("Connection successful!")
    except Exception as e:
        print(f"Connection failed: {e}")

if __name__ == "__main__":
    test_conn()
