This commit is contained in:
team3
2026-07-24 11:23:18 +02:00
parent cb68cd671b
commit 1b054497ed
49 changed files with 935 additions and 408 deletions

View File

@@ -2,6 +2,7 @@
architektonisch, R8), WAL, kurze Transaktionen. Zustand liegt NUR hier —
Resume = Prozess neu starten, fertige Tasks überspringen."""
import json
import re
import sqlite3
import threading
from datetime import datetime, timezone
@@ -14,6 +15,13 @@ _lock = threading.RLock()
on_change: Callable[[str, dict], None] | None = None # ws.Hub.push
_LIVE_TABELLEN = {"topics", "runs", "tasks", "gate_laeufe", "befunde"}
_RUN_TABELLEN = {"topics", "runs"} # ws-Bereich "run", Rest "graph"
# Topic-skopierte Pipeline-Tabellen — EINE Wahrheit für Reset (main.py)
PIPELINE_TABELLEN = ("tasks", "gate_laeufe", "quellen", "soll", "atome",
"kanten", "lernziele", "bausteine", "kapitel")
_TABELLE_RE = re.compile(
r"^\s*(?:UPDATE|DELETE\s+FROM|INSERT(?:\s+OR\s+\w+)?\s+INTO)\s+(\w+)",
re.IGNORECASE)
SCHEMA = """
CREATE TABLE IF NOT EXISTS topics(
@@ -50,8 +58,8 @@ CREATE TABLE IF NOT EXISTS quellen(
id INTEGER PRIMARY KEY, topic TEXT, titel TEXT DEFAULT '', url TEXT DEFAULT '',
url_norm TEXT DEFAULT '', backend TEXT DEFAULT '', snapshot TEXT DEFAULT '',
roh TEXT DEFAULT '', hash TEXT DEFAULT '', runde INTEGER DEFAULT 0,
zweck TEXT DEFAULT 'korpus', status TEXT DEFAULT 'neu', grund TEXT DEFAULT '',
atome_stand TEXT DEFAULT '', UNIQUE(topic, url_norm));
zweck TEXT DEFAULT 'korpus', soll_id INTEGER, status TEXT DEFAULT 'neu',
grund TEXT DEFAULT '', atome_stand TEXT DEFAULT '', UNIQUE(topic, url_norm));
CREATE TABLE IF NOT EXISTS soll(
id INTEGER PRIMARY KEY, topic TEXT, punkt TEXT, status TEXT DEFAULT 'kandidat',
belege TEXT DEFAULT '[]', kapitel_id INTEGER, geprueft TEXT DEFAULT '[]',
@@ -109,7 +117,8 @@ def connect(pfad: str | None = None) -> None:
for migration in ( # Mini-Migrationen für Bestands-DBs
"ALTER TABLE atome ADD COLUMN soll_geprueft INTEGER DEFAULT 0",
"ALTER TABLE topics ADD COLUMN quellen_max INTEGER",
"ALTER TABLE soll ADD COLUMN verdichtet INTEGER DEFAULT 0"):
"ALTER TABLE soll ADD COLUMN verdichtet INTEGER DEFAULT 0",
"ALTER TABLE quellen ADD COLUMN soll_id INTEGER"):
try:
_conn.execute(migration)
except sqlite3.OperationalError:
@@ -156,8 +165,8 @@ def execute(sql: str, *args) -> int:
with _lock:
cur = _conn.execute(sql, args)
_conn.commit()
tabelle = sql.split()[2] if sql.lstrip().upper().startswith(("UPDATE",)) else ""
_notify(tabelle.lower(), {})
m = _TABELLE_RE.match(sql) # UPDATE/DELETE/INSERT — nicht Positions-Raten
_notify(m.group(1).lower() if m else "", {})
return cur.rowcount