This commit is contained in:
Team3
2026-05-29 17:58:43 +02:00
parent a826e9f6b3
commit 067d7229de
8 changed files with 183 additions and 14 deletions

View File

@@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS bausteine (
description TEXT NOT NULL DEFAULT '',
purpose TEXT NOT NULL DEFAULT '',
example TEXT NOT NULL DEFAULT '',
sort_order INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
)
@@ -62,6 +63,10 @@ async def init_db():
columns = {row[1] for row in await cursor.fetchall()}
if "instructions" not in columns:
await db.execute("ALTER TABLE guides ADD COLUMN instructions TEXT NOT NULL DEFAULT ''")
cursor = await db.execute("PRAGMA table_info(bausteine)")
columns = {row[1] for row in await cursor.fetchall()}
if "sort_order" not in columns:
await db.execute("ALTER TABLE bausteine ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0")
await db.execute(
"UPDATE guides SET status = 'error', progress = NULL, error_msg = 'Server-Neustart' "
"WHERE status IN ('queued', 'generating')"
@@ -153,12 +158,22 @@ async def create_baustein(baustein: dict) -> dict:
async def list_bausteine(topic: str) -> list[dict]:
db = await get_db()
cursor = await db.execute(
"SELECT * FROM bausteine WHERE topic = ? ORDER BY created_at ASC", (topic,)
"SELECT * FROM bausteine WHERE topic = ? ORDER BY sort_order ASC, created_at ASC", (topic,)
)
rows = await cursor.fetchall()
return [_row_to_dict(row, cursor) for row in rows]
async def update_baustein_sort_orders(topic: str, order_map: dict) -> None:
db = await get_db()
for baustein_id, order in order_map.items():
await db.execute(
"UPDATE bausteine SET sort_order = ? WHERE id = ? AND topic = ?",
(order, baustein_id, topic),
)
await db.commit()
async def get_baustein(baustein_id: str) -> dict | None:
db = await get_db()
cursor = await db.execute("SELECT * FROM bausteine WHERE id = ?", (baustein_id,))