88bdf6f34b
- Split monolithic app.py into server/api/ routers - Add Pydantic schemas for input validation - Add /agent/* API with separate AGENT_TOKEN auth - Replace static schema.sql with versioned migrations (datenerhaltend) - Add tools/backup_db.py for SQLite backups - Add Dockerfile HEALTHCHECK and compose.yml AGENT_TOKEN env - Add pytest tests for user and agent API - Update README with API docs and deployment safety notes - Bump version to 1.2.0
31 lines
676 B
Python
31 lines
676 B
Python
from __future__ import annotations
|
|
|
|
import pathlib
|
|
import uuid
|
|
from datetime import UTC, datetime
|
|
|
|
import aiosqlite
|
|
|
|
from server.settings import settings
|
|
|
|
|
|
def new_id() -> str:
|
|
return str(uuid.uuid4())
|
|
|
|
|
|
def utc_now_iso() -> str:
|
|
return datetime.now(UTC).replace(microsecond=0).isoformat()
|
|
|
|
|
|
async def get_db() -> aiosqlite.Connection:
|
|
pathlib.Path(settings.db_path).parent.mkdir(parents=True, exist_ok=True)
|
|
db = await aiosqlite.connect(settings.db_path)
|
|
await db.execute("PRAGMA foreign_keys = ON;")
|
|
return db
|
|
|
|
|
|
async def ensure_schema(db: aiosqlite.Connection) -> None:
|
|
from server.migrations import run_migrations
|
|
|
|
await run_migrations(db)
|