feat: Credits-System mit Verbrauchsanzeige im User-Dropdown
- DB-Migration: credits_total/credits_used/cost_per_credit auf licenses, token_usage_monthly Tabelle - Orchestrator: Monatliche Token-Aggregation + Credits-Abzug nach Refresh - Auth: Credits-Daten im /me Endpoint + Bugfix fehlende Klammer in get() - Frontend: Credits-Balken im User-Dropdown mit Farbwechsel Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dieser Commit ist enthalten in:
@@ -582,7 +582,42 @@ async def init_db():
|
||||
await db.commit()
|
||||
logger.info("Migration: article_locations-Tabelle erstellt")
|
||||
|
||||
# Verwaiste running-Eintraege beim Start als error markieren (aelter als 15 Min)
|
||||
|
||||
# Migration: Credits-System fuer Lizenzen
|
||||
cursor = await db.execute("PRAGMA table_info(licenses)")
|
||||
columns = [row[1] for row in await cursor.fetchall()]
|
||||
if "token_budget_usd" not in columns:
|
||||
await db.execute("ALTER TABLE licenses ADD COLUMN token_budget_usd REAL")
|
||||
await db.execute("ALTER TABLE licenses ADD COLUMN credits_total INTEGER")
|
||||
await db.execute("ALTER TABLE licenses ADD COLUMN credits_used REAL DEFAULT 0")
|
||||
await db.execute("ALTER TABLE licenses ADD COLUMN cost_per_credit REAL")
|
||||
await db.execute("ALTER TABLE licenses ADD COLUMN budget_warning_percent INTEGER DEFAULT 80")
|
||||
await db.commit()
|
||||
logger.info("Migration: Credits-System zu Lizenzen hinzugefuegt")
|
||||
|
||||
# Migration: Token-Usage-Monatstabelle
|
||||
cursor = await db.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='token_usage_monthly'")
|
||||
if not await cursor.fetchone():
|
||||
await db.execute("""
|
||||
CREATE TABLE token_usage_monthly (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
organization_id INTEGER REFERENCES organizations(id),
|
||||
year_month TEXT NOT NULL,
|
||||
input_tokens INTEGER DEFAULT 0,
|
||||
output_tokens INTEGER DEFAULT 0,
|
||||
cache_creation_tokens INTEGER DEFAULT 0,
|
||||
cache_read_tokens INTEGER DEFAULT 0,
|
||||
total_cost_usd REAL DEFAULT 0.0,
|
||||
api_calls INTEGER DEFAULT 0,
|
||||
refresh_count INTEGER DEFAULT 0,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(organization_id, year_month)
|
||||
)
|
||||
""")
|
||||
await db.commit()
|
||||
logger.info("Migration: token_usage_monthly Tabelle erstellt")
|
||||
|
||||
# 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',
|
||||
completed_at = CURRENT_TIMESTAMP
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren