Skip to content

Commit c4dc113

Browse files
committed
Convert PostgreSQL database URLs to asyncpg format for SQLAlchemy compatibility.
1 parent fd0a2b5 commit c4dc113

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

server/app/database.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
# Default to SQLite for local development
66
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///./test.db")
77

8+
# Render provides postgres:// but SQLAlchemy async needs postgresql+asyncpg://
9+
if DATABASE_URL.startswith("postgres://"):
10+
DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql+asyncpg://", 1)
11+
elif DATABASE_URL.startswith("postgresql://"):
12+
DATABASE_URL = DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://", 1)
13+
814
engine = create_async_engine(
915
DATABASE_URL,
1016
echo=True,

0 commit comments

Comments
 (0)