RyZ commited on
Commit Β·
d852d80
1
Parent(s): 2e0b5ad
deploy: fix hf deploy
Browse files
src/infrastructure/database/connection.py
CHANGED
|
@@ -28,9 +28,34 @@ from sqlalchemy.ext.asyncio import (
|
|
| 28 |
|
| 29 |
from src.shared.config import get_settings
|
| 30 |
from src.shared.logger import get_logger
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
logger = get_logger(__name__)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# ββ Module-level singletons (created once per process) βββββββββββββββββββββββ
|
| 35 |
_engine: AsyncEngine | None = None
|
| 36 |
_session_factory: async_sessionmaker[AsyncSession] | None = None
|
|
|
|
| 28 |
|
| 29 |
from src.shared.config import get_settings
|
| 30 |
from src.shared.logger import get_logger
|
| 31 |
+
from sqlalchemy.ext.compiler import compiles
|
| 32 |
+
from sqlalchemy.dialects.postgresql import JSONB
|
| 33 |
+
from sqlalchemy.sql.elements import TextClause
|
| 34 |
|
| 35 |
logger = get_logger(__name__)
|
| 36 |
|
| 37 |
+
# ββ SQLite Compatibility Compilers βββββββββββββββββββββββββββββββββββββββββββ
|
| 38 |
+
# Registers global overrides to compile PostgreSQL-specific DDL for SQLite fallback.
|
| 39 |
+
|
| 40 |
+
@compiles(JSONB, "sqlite")
|
| 41 |
+
def compile_jsonb_sqlite(type_, compiler, **kw):
|
| 42 |
+
"""Compile JSONB to standard JSON in SQLite."""
|
| 43 |
+
return "JSON"
|
| 44 |
+
|
| 45 |
+
@compiles(TextClause, "sqlite")
|
| 46 |
+
def compile_text_sqlite(element, compiler, **kw):
|
| 47 |
+
"""Compile gen_random_uuid() to random hex blob in SQLite."""
|
| 48 |
+
if element.text == "gen_random_uuid()":
|
| 49 |
+
return (
|
| 50 |
+
"(lower(hex(randomblob(4))) || '-' || "
|
| 51 |
+
"lower(hex(randomblob(2))) || '-4' || "
|
| 52 |
+
"substr(lower(hex(randomblob(2))),2) || '-' || "
|
| 53 |
+
"substr('89ab',abs(random()) % 4 + 1, 1) || "
|
| 54 |
+
"substr(lower(hex(randomblob(2))),2) || '-' || "
|
| 55 |
+
"lower(hex(randomblob(6))))"
|
| 56 |
+
)
|
| 57 |
+
return element.text
|
| 58 |
+
|
| 59 |
# ββ Module-level singletons (created once per process) βββββββββββββββββββββββ
|
| 60 |
_engine: AsyncEngine | None = None
|
| 61 |
_session_factory: async_sessionmaker[AsyncSession] | None = None
|
tests/integration/test_api.py
CHANGED
|
@@ -23,22 +23,7 @@ os.environ["RABBITMQ_URL"] = "amqp://guest:guest@localhost:5672/"
|
|
| 23 |
os.environ["USE_MOCK_MODEL"] = "true"
|
| 24 |
os.environ["DEBUG"] = "true"
|
| 25 |
|
| 26 |
-
# SQLite compatibility
|
| 27 |
-
from sqlalchemy.ext.compiler import compiles
|
| 28 |
-
from sqlalchemy.dialects.postgresql import JSONB
|
| 29 |
-
from sqlalchemy.sql.elements import TextClause
|
| 30 |
-
|
| 31 |
-
@compiles(JSONB, "sqlite")
|
| 32 |
-
def compile_jsonb_sqlite(type_, compiler, **kw):
|
| 33 |
-
return "JSON"
|
| 34 |
-
|
| 35 |
-
@compiles(TextClause, "sqlite")
|
| 36 |
-
def compile_text_sqlite(element, compiler, **kw):
|
| 37 |
-
if element.text == "gen_random_uuid()":
|
| 38 |
-
return "(lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))))"
|
| 39 |
-
return element.text
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
from httpx import ASGITransport, AsyncClient
|
| 44 |
|
|
|
|
| 23 |
os.environ["USE_MOCK_MODEL"] = "true"
|
| 24 |
os.environ["DEBUG"] = "true"
|
| 25 |
|
| 26 |
+
# SQLite compatibility compilers are now globally registered in connection.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
from httpx import ASGITransport, AsyncClient
|
| 29 |
|