Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion apps/api/app/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@

from .config import settings

engine = create_engine(settings.database_url, future=True)

def _normalize_db_url(url: str) -> str:
# psycopg v3 (installed via psycopg[binary]) requires the
# "postgresql+psycopg://" scheme. SQLAlchemy defaults the bare
# "postgresql://"/"postgres://" scheme to psycopg2, which is not installed.
if url.startswith("postgres://"):
url = "postgresql://" + url[len("postgres://"):]
if url.startswith("postgresql://"):
url = "postgresql+psycopg://" + url[len("postgresql://"):]
return url


engine = create_engine(_normalize_db_url(settings.database_url), future=True)
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False, future=True)
Base = declarative_base()

Expand Down
Loading