From 04e3381bd7b90dcddcf19ab2317c6a3d7f2eb1ff Mon Sep 17 00:00:00 2001 From: "railway-app[bot]" <68434857+railway-app[bot]@users.noreply.github.com> Date: Sat, 11 Jul 2026 17:39:13 +0000 Subject: [PATCH] fix: normalize DATABASE_URL to postgresql+psycopg:// scheme --- apps/api/app/core/db.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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()