feat: fastapi-backend mit healthcheck und alembic-basis
- GET /api/health prüft die Datenbankverbindung - SQLite im WAL-Modus unter /data/app.db - Auslieferung des gebauten Frontends mit SPA-Fallback - leere Basis-Migration, Tests mit pytest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ff666175d0
commit
8e6ef05304
15 files changed
+414
No files matched your search
@@ -0,0 +1,38 @@
|
||||
from collections.abc import Iterator
|
||||
from functools import lru_cache
|
||||
|
||||
from sqlalchemy import Engine, create_engine, event
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
||||
from app.config import get_settings
|
||||
|
||||
|
||||
def _set_sqlite_pragmas(dbapi_connection, _connection_record) -> None:
|
||||
cursor = dbapi_connection.cursor()
|
||||
cursor.execute("PRAGMA journal_mode=WAL")
|
||||
cursor.execute("PRAGMA foreign_keys=ON")
|
||||
cursor.execute("PRAGMA busy_timeout=5000")
|
||||
cursor.close()
|
||||
|
||||
|
||||
def create_db_engine(url: str) -> Engine:
|
||||
engine = create_engine(url, connect_args={"check_same_thread": False})
|
||||
event.listen(engine, "connect", _set_sqlite_pragmas)
|
||||
return engine
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_engine() -> Engine:
|
||||
settings = get_settings()
|
||||
settings.data_dir.mkdir(parents=True, exist_ok=True)
|
||||
return create_db_engine(settings.database_url)
|
||||
|
||||
|
||||
@lru_cache
|
||||
def _session_factory() -> sessionmaker[Session]:
|
||||
return sessionmaker(bind=get_engine(), expire_on_commit=False)
|
||||
|
||||
|
||||
def get_db() -> Iterator[Session]:
|
||||
with _session_factory()() as session:
|
||||
yield session
|
||||
Reference in new issue
Block a user