-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_soft_delete.py
More file actions
63 lines (53 loc) · 2.88 KB
/
demo_soft_delete.py
File metadata and controls
63 lines (53 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
"""
Demo script to show soft delete behavior
"""
from datetime import datetime
from app import app, db, User, Presentation
def demo_soft_delete():
print("=== Demo: Soft Delete Verhalten ===\n")
with app.app_context():
# Zeige alle Präsentationen (auch gelöschte)
all_presentations = Presentation.query.all()
active_presentations = Presentation.query.filter_by(is_deleted=False).all()
deleted_presentations = Presentation.query.filter_by(is_deleted=True).all()
print(f"📊 Datenbank-Statistiken:")
print(f" Gesamt: {len(all_presentations)} Präsentationen")
print(f" Aktiv: {len(active_presentations)} Präsentationen")
print(f" Gelöscht: {len(deleted_presentations)} Präsentationen")
if deleted_presentations:
print(f"\n🗑️ Gelöschte Präsentationen:")
for p in deleted_presentations:
deleted_by = User.query.get(p.deleted_by_user_id)
deleted_by_name = deleted_by.username if deleted_by else "Unbekannt"
print(f" - '{p.title}' (ID: {p.id})")
print(f" Gelöscht am: {p.deleted_at}")
print(f" Gelöscht von: {deleted_by_name}")
print(f" Access Code: {p.access_code} (nicht mehr erreichbar)")
print()
if active_presentations:
print(f"✅ Aktive Präsentationen:")
for p in active_presentations:
creator = User.query.get(p.user_id)
creator_name = creator.username if creator else "Unbekannt"
print(f" - '{p.title}' (ID: {p.id})")
print(f" Erstellt von: {creator_name}")
print(f" Access Code: {p.access_code}")
print(f" Erreichbar unter: /p/{p.access_code}")
print()
# Demo Dashboard-Verhalten
users_with_presentations = User.query.join(Presentation, User.id == Presentation.user_id).distinct().all()
if users_with_presentations:
print(f"👤 Dashboard-Ansicht für Benutzer:")
for user in users_with_presentations:
dashboard_presentations = Presentation.get_active_by_user(user.id)
print(f" {user.username}: {len(dashboard_presentations)} aktive Präsentationen sichtbar")
# Zeige Vorteile von Soft Delete
print(f"\n💡 Vorteile des Soft Delete Systems:")
print(f" ✓ Präsentationen bleiben in der Datenbank erhalten")
print(f" ✓ Feedbacks und KI-Antworten gehen nicht verloren")
print(f" ✓ Audit-Trail: Wer hat wann gelöscht")
print(f" ✓ Möglichkeit zur Wiederherstellung (falls gewünscht)")
print(f" ✓ Keine Dateninkonsistenzen durch Fremdschlüssel")
if __name__ == "__main__":
demo_soft_delete()