chore: switch to all-SQLite stack (drop Postgres service)
This commit is contained in:
parent
74831483eb
commit
7d5ade6b6a
12 changed files with 104 additions and 62 deletions
|
|
@ -1,6 +1,7 @@
|
|||
"""Database engine, sessions, and FastAPI dependency."""
|
||||
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
from sqlalchemy import Engine
|
||||
from sqlmodel import Session, SQLModel, create_engine
|
||||
|
|
@ -10,11 +11,23 @@ from .settings import settings
|
|||
_engine: Engine | None = None
|
||||
|
||||
|
||||
def _engine_kwargs(url: str) -> dict:
|
||||
if url.startswith("sqlite"):
|
||||
# FastAPI runs sync endpoints in a threadpool; connections are shared
|
||||
# across threads, so defer the same-thread check. File-based SQLite
|
||||
# needs an existing parent dir (SQLite won't create it).
|
||||
return {"connect_args": {"check_same_thread": False}}
|
||||
return {}
|
||||
|
||||
|
||||
def get_engine(url: str | None = None) -> Engine:
|
||||
"""Process-wide engine singleton (override URL in tests via settings)."""
|
||||
global _engine
|
||||
if _engine is None:
|
||||
_engine = create_engine(url or settings.database_url)
|
||||
url = url or settings.database_url
|
||||
if url.startswith("sqlite:///") and not url.startswith("sqlite:///:memory:"):
|
||||
Path(url.removeprefix("sqlite:///")).parent.mkdir(parents=True, exist_ok=True)
|
||||
_engine = create_engine(url, **_engine_kwargs(url))
|
||||
return _engine
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,13 @@ class Settings(BaseSettings):
|
|||
version: str = "0.1.0"
|
||||
debug: bool = False
|
||||
|
||||
database_url: str = "postgresql+psycopg://kirche:kirche@localhost:5432/kirche_einfach"
|
||||
test_database_url: str = (
|
||||
"postgresql+psycopg://kirche:kirche@localhost:5432/kirche_einfach_test"
|
||||
)
|
||||
# App database (SQLite file). Override via DATABASE_URL for other engines.
|
||||
database_url: str = str(REPO_ROOT / "backend" / "data" / "kirche.db")
|
||||
|
||||
# Canonical flow definitions (source of truth): one Langflow export per file.
|
||||
flows_dir: str = str(REPO_ROOT / "backend" / "flows")
|
||||
# Auto-reconcile backend/flows into the DB + LFX while the API is running.
|
||||
flows_watch_enabled: bool = True
|
||||
|
||||
langflow_url: str = "http://localhost:7860"
|
||||
langflow_api_key: str = ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue