From 6bcc388b070e1219e05f2b794ac51148471b26ca Mon Sep 17 00:00:00 2001 From: UserIsMH Date: Sun, 8 Jun 2025 00:21:12 +0200 Subject: [PATCH] Batch Keys Gefixt --- JOURNAL.md | 28 +++++++++++++++++++++++++++- v2_adminpanel/app.py | 4 ++-- v2_adminpanel/init.sql | 15 ++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/JOURNAL.md b/JOURNAL.md index 99a7ea1..c1e4751 100644 --- a/JOURNAL.md +++ b/JOURNAL.md @@ -1094,4 +1094,30 @@ Die Session-Daten werden erst gefüllt, wenn der License Server API implementier - ✅ Automatische Berechnung funktioniert - ✅ Frontend zeigt berechnetes Datum sofort an - ✅ Backend validiert die Berechnung -- ✅ Standardwert (1 Jahr) voreingestellt \ No newline at end of file +- ✅ Standardwert (1 Jahr) voreingestellt + +## 2025-01-06: Bugfix - created_at für licenses Tabelle + +**Problem:** +- Batch-Generierung schlug fehl mit "Fehler bei der Batch-Generierung!" +- INSERT Statement versuchte `created_at` zu setzen, aber Spalte existierte nicht +- Inkonsistenz: Einzellizenzen hatten kein created_at, Batch-Lizenzen versuchten es zu setzen + +**Lösung:** +1. **Datenbank-Schema erweitert:** + - `created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP` zur licenses Tabelle hinzugefügt + - Migration für bestehende Datenbanken implementiert + - Konsistent mit customers Tabelle +2. **Code bereinigt:** + - Explizites `created_at` aus Batch-INSERT entfernt + - Datenbank setzt nun automatisch den Zeitstempel bei ALLEN Lizenzen + +**Änderungen:** +- `init.sql`: created_at Spalte zur licenses Tabelle mit DEFAULT-Wert +- `init.sql`: Migration für bestehende Datenbanken +- `app.py`: Entfernt explizites created_at aus batch_licenses() + +**Status:** +- ✅ Alle Lizenzen haben nun automatisch einen Erstellungszeitstempel +- ✅ Batch-Generierung funktioniert wieder +- ✅ Konsistente Zeitstempel für Audit-Zwecke \ No newline at end of file diff --git a/v2_adminpanel/app.py b/v2_adminpanel/app.py index ff1756b..c434209 100644 --- a/v2_adminpanel/app.py +++ b/v2_adminpanel/app.py @@ -1213,8 +1213,8 @@ def batch_licenses(): # Lizenz einfügen cur.execute(""" INSERT INTO licenses (license_key, customer_id, license_type, - valid_from, valid_until, is_active, created_at) - VALUES (%s, %s, %s, %s, %s, true, NOW()) + valid_from, valid_until, is_active) + VALUES (%s, %s, %s, %s, %s, true) RETURNING id """, (license_key, customer_id, license_type, valid_from, valid_until)) license_id = cur.fetchone()[0] diff --git a/v2_adminpanel/init.sql b/v2_adminpanel/init.sql index c363219..73a863c 100644 --- a/v2_adminpanel/init.sql +++ b/v2_adminpanel/init.sql @@ -16,7 +16,8 @@ CREATE TABLE IF NOT EXISTS licenses ( license_type TEXT NOT NULL, valid_from DATE NOT NULL, valid_until DATE NOT NULL, - is_active BOOLEAN DEFAULT TRUE + is_active BOOLEAN DEFAULT TRUE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE IF NOT EXISTS sessions ( @@ -86,3 +87,15 @@ CREATE TABLE IF NOT EXISTS login_attempts ( -- Index für schnelle Abfragen CREATE INDEX idx_login_attempts_blocked_until ON login_attempts(blocked_until); CREATE INDEX idx_login_attempts_last_attempt ON login_attempts(last_attempt DESC); + +-- Migration: Füge created_at zu licenses hinzu, falls noch nicht vorhanden +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.columns + WHERE table_name = 'licenses' AND column_name = 'created_at') THEN + ALTER TABLE licenses ADD COLUMN created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP; + + -- Setze created_at für bestehende Einträge auf das valid_from Datum + UPDATE licenses SET created_at = valid_from WHERE created_at IS NULL; + END IF; +END $$;