fix: normalize DATABASE_URL for Railway Postgres (postgres:// → postgresql+asyncpg://)

Railway Postgres gives postgres:// but SQLAlchemy asyncpg needs
postgresql+asyncpg://. This was the root cause of all Railway crashes.

https://claude.ai/code/session_01W1rJthWDkasijTdXCfxVHs
This commit is contained in:
Claude 2026-04-25 21:43:27 +00:00
parent cbce696868
commit 0ffba2167c
No known key found for this signature in database

View File

@ -16,7 +16,14 @@ def _get_db_url() -> str:
break break
except FileNotFoundError: except FileNotFoundError:
continue continue
return url or "sqlite+aiosqlite:///./dealix.db" if not url:
return "sqlite+aiosqlite:///./dealix.db"
# Railway Postgres gives postgres:// but SQLAlchemy needs postgresql+asyncpg://
if url.startswith("postgres://"):
url = url.replace("postgres://", "postgresql+asyncpg://", 1)
elif url.startswith("postgresql://"):
url = url.replace("postgresql://", "postgresql+asyncpg://", 1)
return url
_DB_URL = _get_db_url() _DB_URL = _get_db_url()