diff --git a/apps/api/app/core/db.py b/apps/api/app/core/db.py index 3244199..1dec5a5 100644 --- a/apps/api/app/core/db.py +++ b/apps/api/app/core/db.py @@ -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()