store: auto-migrate old KGs (edges.origin_question); machine: abort honestly on dead LM

- KnowledgeStore._migrate(): idempotent additive migration on open — a
  pre-2026-10-19 KG no longer crashes the set gate with 'no such column'
- _lm_dead(): transport/timeout deaths abort the run with notes (no answer
  beats a made-up one); code bugs still crash loudly
- tests: migration from a hand-built old-schema store; LM-death abort (24/24)
This commit is contained in:
2026-10-19 12:11:59 +02:00
parent e5482bd092
commit b14915079e
4 changed files with 109 additions and 1 deletions
+11
View File
@@ -87,9 +87,20 @@ class KnowledgeStore:
self.path.parent.mkdir(parents=True, exist_ok=True)
self.db = sqlite3.connect(self.path)
self.db.executescript(SCHEMA)
self._migrate()
self.db.commit()
self._mirror: Path | None = None
def _migrate(self) -> None:
"""Idempotent, additive migrations. CREATE TABLE IF NOT EXISTS never
upgrades an existing file, so stores predating a column change must
be migrated here or every query touching the column crashes
(2026-10-19: edges.origin_question, added with the set gate)."""
cols = {r[1] for r in self.db.execute("PRAGMA table_info(edges)")}
if "origin_question" not in cols:
self.db.execute("ALTER TABLE edges ADD COLUMN origin_question TEXT")
self.db.commit()
# ---- documents & quotes ------------------------------------------------
def add_document(self, url: str, title: str, fetched_at: str, sha256: str,
trusted: bool = True, source: str = "wikipedia") -> int: