feat: Add CI workflow for running tests and update database URL handling
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.engine import URL
|
||||
from sqlalchemy.orm import declarative_base, sessionmaker
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
@@ -14,8 +13,8 @@ def _build_database_url() -> str:
|
||||
Falls back to `DATABASE_URL` for backward compatibility.
|
||||
"""
|
||||
|
||||
legacy_url = os.environ.get("DATABASE_URL")
|
||||
if legacy_url:
|
||||
legacy_url = os.environ.get("DATABASE_URL", "")
|
||||
if legacy_url and legacy_url.strip() != "":
|
||||
return legacy_url
|
||||
|
||||
driver = os.environ.get("DATABASE_DRIVER", "postgresql")
|
||||
@@ -42,17 +41,12 @@ def _build_database_url() -> str:
|
||||
f"granular variables ({', '.join(missing)})"
|
||||
)
|
||||
|
||||
url = URL.create(
|
||||
drivername=driver,
|
||||
username=user,
|
||||
password=password,
|
||||
host=host,
|
||||
port=int(port) if port else None,
|
||||
database=database,
|
||||
)
|
||||
|
||||
url = f"{driver}://{user}:{password}@{host}"
|
||||
if port:
|
||||
url += f":{port}"
|
||||
url += f"/{database}"
|
||||
if schema:
|
||||
url = url.set(query={"options": f"-csearch_path={schema}"})
|
||||
url += f"?options=-csearch_path={schema}"
|
||||
|
||||
return str(url)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user