Spaces:
Runtime error
Runtime error
Isolate MediaRouter social DB connections in mediarouter schema
#8
by basyx - opened
- app/social/database.py +10 -2
app/social/database.py
CHANGED
|
@@ -73,7 +73,11 @@ class SocialDatabase:
|
|
| 73 |
self.database_url = normalize_async_database_url(settings.resolved_social_database_url)
|
| 74 |
# Supabase/PgBouncer transaction pooling requires asyncpg's prepared
|
| 75 |
# statement cache to be disabled to avoid stale statement-name reuse.
|
| 76 |
-
connect_args =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
self.engine: AsyncEngine = create_async_engine(
|
| 78 |
self.database_url, pool_pre_ping=True, connect_args=connect_args
|
| 79 |
)
|
|
@@ -86,7 +90,11 @@ class SocialDatabase:
|
|
| 86 |
self.worker_engine: AsyncEngine | None = None
|
| 87 |
self.worker_session_factory: async_sessionmaker[AsyncSession] | None = None
|
| 88 |
if self.worker_database_url:
|
| 89 |
-
worker_connect_args =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
self.worker_engine = create_async_engine(
|
| 91 |
self.worker_database_url, pool_pre_ping=True, connect_args=worker_connect_args
|
| 92 |
)
|
|
|
|
| 73 |
self.database_url = normalize_async_database_url(settings.resolved_social_database_url)
|
| 74 |
# Supabase/PgBouncer transaction pooling requires asyncpg's prepared
|
| 75 |
# statement cache to be disabled to avoid stale statement-name reuse.
|
| 76 |
+
connect_args = (
|
| 77 |
+
{"statement_cache_size": 0, "server_settings": {"search_path": "mediarouter"}}
|
| 78 |
+
if self.database_url.startswith(("postgresql", "postgres"))
|
| 79 |
+
else {}
|
| 80 |
+
)
|
| 81 |
self.engine: AsyncEngine = create_async_engine(
|
| 82 |
self.database_url, pool_pre_ping=True, connect_args=connect_args
|
| 83 |
)
|
|
|
|
| 90 |
self.worker_engine: AsyncEngine | None = None
|
| 91 |
self.worker_session_factory: async_sessionmaker[AsyncSession] | None = None
|
| 92 |
if self.worker_database_url:
|
| 93 |
+
worker_connect_args = (
|
| 94 |
+
{"statement_cache_size": 0, "server_settings": {"search_path": "mediarouter"}}
|
| 95 |
+
if self.worker_database_url.startswith(("postgresql", "postgres"))
|
| 96 |
+
else {}
|
| 97 |
+
)
|
| 98 |
self.worker_engine = create_async_engine(
|
| 99 |
self.worker_database_url, pool_pre_ping=True, connect_args=worker_connect_args
|
| 100 |
)
|