feat(settings): organization_settings KV-Tabelle + org_settings Helper

Neue Tabelle organization_settings (organization_id, key, value) als KV-Store
fuer Org-spezifische Konfiguration. Erster Use-Case: output_language (de|en).
Bestandsorgs werden per Migration auf de gesetzt.

Helper services/org_settings.py mit get_org_setting / set_org_setting /
get_org_language / language_display. In-Memory-Cache TTL 60s.

Phase 1 von 8 (eng_demo / Org-Sprache).
Dieser Commit ist enthalten in:
Claude Code
2026-05-13 20:46:04 +00:00
Ursprung 5ec4480598
Commit d27d586003
2 geänderte Dateien mit 139 neuen und 0 gelöschten Zeilen

Datei anzeigen

@@ -345,6 +345,15 @@ CREATE TABLE IF NOT EXISTS network_generation_log (
error_message TEXT,
tenant_id INTEGER REFERENCES organizations(id)
);
CREATE TABLE IF NOT EXISTS organization_settings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
organization_id INTEGER NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
key TEXT NOT NULL,
value TEXT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(organization_id, key)
);
"""
@@ -782,6 +791,32 @@ async def init_db():
await db.commit()
logger.info("Migration: token_usage_monthly Tabelle erstellt")
# Migration: organization_settings KV-Tabelle (pro Org Sprache, ggf. spaeter weitere Settings)
cursor = await db.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='organization_settings'")
if not await cursor.fetchone():
await db.execute("""
CREATE TABLE organization_settings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
organization_id INTEGER NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
key TEXT NOT NULL,
value TEXT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(organization_id, key)
)
""")
await db.commit()
logger.info("Migration: organization_settings Tabelle erstellt")
# Default-Setting output_language='de' fuer Orgs ohne Eintrag
await db.execute("""
INSERT OR IGNORE INTO organization_settings (organization_id, key, value)
SELECT id, 'output_language', 'de' FROM organizations
WHERE id NOT IN (
SELECT organization_id FROM organization_settings WHERE key='output_language'
)
""")
await db.commit()
# Verwaiste running-Eintraege beim Start als error markieren (aelter als 15 Min)
await db.execute(
"""UPDATE refresh_log SET status = 'error', error_message = 'Verwaist beim Neustart',