This commit is contained in:
root
2026-06-28 12:03:24 +00:00
parent 8c69c44b37
commit 5b71fcbcd7

View File

@@ -103,7 +103,7 @@ CREATE TABLE IF NOT EXISTS subbausteine (
nennungen INTEGER NOT NULL DEFAULT 1,
stufe TEXT,
relevanz TEXT,
fakten TEXT,
fakten TEXT NOT NULL DEFAULT '',
status TEXT NOT NULL DEFAULT 'kandidat',
updated_at TEXT NOT NULL,
PRIMARY KEY (topic, baustein_norm, sub_norm)
@@ -263,7 +263,7 @@ async def init_db():
await db.execute("DROP TABLE frage_muster")
await db.execute(CREATE_FRAGE_MUSTER)
try: # Migration: subbausteine.fakten (Quell-Fakten je Sub, JSON-Blob) — Extract-once-Grounding.
await db.execute("ALTER TABLE subbausteine ADD COLUMN fakten TEXT") # nullable: COALESCE schützt Bestand
await db.execute("ALTER TABLE subbausteine ADD COLUMN fakten TEXT NOT NULL DEFAULT ''") # DEFAULT '' nötig für NOT NULL beim ADD COLUMN
except aiosqlite.OperationalError:
pass
# Migration: alte vertiefungen-Tabelle → baustein_texte (Bestand = lange Form, art 'deepdive')
@@ -784,12 +784,12 @@ async def put_subbaustein(topic: str, baustein_norm: str, sub_norm: str, baustei
db = await get_db()
await db.execute(
"""INSERT INTO subbausteine (topic, baustein_norm, sub_norm, baustein, sub_titel, nennungen, stufe, relevanz, fakten, status, updated_at)
VALUES (?, ?, ?, ?, ?, 1, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, 1, ?, ?, COALESCE(?, ''), ?, ?)
ON CONFLICT(topic, baustein_norm, sub_norm) DO UPDATE SET
baustein = excluded.baustein, sub_titel = excluded.sub_titel,
stufe = COALESCE(excluded.stufe, subbausteine.stufe),
relevanz = COALESCE(excluded.relevanz, subbausteine.relevanz),
fakten = COALESCE(excluded.fakten, subbausteine.fakten),
fakten = COALESCE(NULLIF(excluded.fakten, ''), subbausteine.fakten),
status = excluded.status, updated_at = excluded.updated_at""",
(topic, baustein_norm, sub_norm, baustein, sub_titel, stufe, relevanz, fakten, status, _now()),
)