Spaces:
Running
Running
Monteeq CI commited on
Commit ·
a5b31c3
1
Parent(s): 154f032
🚀 Deploy from GitHub @ 5a0baa30927c586b1547e22761883ee5bcdf6c05
Browse filesTriggered by: Smasduq
Message: fix: map psycopg2 Postgres URLs to asyncpg for async engine
- app/db/async_session.py +14 -2
app/db/async_session.py
CHANGED
|
@@ -1,13 +1,25 @@
|
|
| 1 |
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
| 2 |
from app.core.config import DATABASE_URL
|
| 3 |
|
| 4 |
-
# Convert
|
| 5 |
if DATABASE_URL.startswith("sqlite"):
|
| 6 |
ASYNC_SQLALCHEMY_DATABASE_URL = DATABASE_URL.replace("sqlite://", "sqlite+aiosqlite://")
|
| 7 |
connect_args = {"check_same_thread": False}
|
| 8 |
extra_engine_args = {}
|
| 9 |
else:
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
connect_args = {"statement_cache_size": 0}
|
| 12 |
extra_engine_args = {"pool_size": 3, "max_overflow": 2}
|
| 13 |
|
|
|
|
| 1 |
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
| 2 |
from app.core.config import DATABASE_URL
|
| 3 |
|
| 4 |
+
# Convert to async driver URLs
|
| 5 |
if DATABASE_URL.startswith("sqlite"):
|
| 6 |
ASYNC_SQLALCHEMY_DATABASE_URL = DATABASE_URL.replace("sqlite://", "sqlite+aiosqlite://")
|
| 7 |
connect_args = {"check_same_thread": False}
|
| 8 |
extra_engine_args = {}
|
| 9 |
else:
|
| 10 |
+
# Handle various Postgres URL formats
|
| 11 |
+
if DATABASE_URL.startswith("postgresql+asyncpg://"):
|
| 12 |
+
ASYNC_SQLALCHEMY_DATABASE_URL = DATABASE_URL
|
| 13 |
+
elif DATABASE_URL.startswith("postgresql+psycopg2://"):
|
| 14 |
+
ASYNC_SQLALCHEMY_DATABASE_URL = DATABASE_URL.replace("postgresql+psycopg2://", "postgresql+asyncpg://")
|
| 15 |
+
elif DATABASE_URL.startswith("postgresql+psycopg://"):
|
| 16 |
+
ASYNC_SQLALCHEMY_DATABASE_URL = DATABASE_URL.replace("postgresql+psycopg://", "postgresql+asyncpg://")
|
| 17 |
+
elif DATABASE_URL.startswith("postgresql://"):
|
| 18 |
+
ASYNC_SQLALCHEMY_DATABASE_URL = DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://")
|
| 19 |
+
elif DATABASE_URL.startswith("postgres://"):
|
| 20 |
+
ASYNC_SQLALCHEMY_DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql+asyncpg://")
|
| 21 |
+
else:
|
| 22 |
+
ASYNC_SQLALCHEMY_DATABASE_URL = DATABASE_URL
|
| 23 |
connect_args = {"statement_cache_size": 0}
|
| 24 |
extra_engine_args = {"pool_size": 3, "max_overflow": 2}
|
| 25 |
|