From 4f58b04a0fff0dc3a6469ac9d8b72cc6b0b81757 Mon Sep 17 00:00:00 2001 From: "matthias.lotz" Date: Sat, 8 Nov 2025 12:05:34 +0100 Subject: [PATCH] feat(db): Add deletion_log table and cleanup indexes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 1 Complete - Database Schema - Add deletion_log table for audit trail (no personal data) - Add performance indexes for cleanup queries: - idx_groups_approved - idx_groups_cleanup (approved, upload_date) - idx_deletion_log_deleted_at (DESC) - idx_deletion_log_year - Table structure: group_id, year, image_count, upload_date, deleted_at, deletion_reason, total_file_size Tasks completed: ✅ 1.1, ✅ 1.2 --- README.md | 2 +- backend/src/database/DatabaseManager.js | 19 ++++++++++++++++ docs/FEATURE_PLAN-delete-unproved-groups.md | 25 ++++++++++----------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index edc6802..7a4f3c9 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This project extends the original [Image-Uploader by vallezw](https://github.com - **Slideshow Display**: Image descriptions shown as overlays during slideshow presentation - **Public Display**: Descriptions visible in public group views and galleries -### Previous Features (January 2025) +### Previous Features (October 2025) - **Drag-and-Drop Image Reordering**: Admins can now reorder images using intuitive drag-and-drop - **Touch-Friendly Interface**: Mobile-optimized controls with always-visible drag handles - **Slideshow Integration**: Custom image order automatically applies to slideshow mode diff --git a/backend/src/database/DatabaseManager.js b/backend/src/database/DatabaseManager.js index 861f4c0..33dd283 100644 --- a/backend/src/database/DatabaseManager.js +++ b/backend/src/database/DatabaseManager.js @@ -115,12 +115,31 @@ class DatabaseManager { } } + // Erstelle Deletion Log Tabelle + await this.run(` + CREATE TABLE IF NOT EXISTS deletion_log ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + group_id TEXT NOT NULL, + year INTEGER NOT NULL, + image_count INTEGER NOT NULL, + upload_date DATETIME NOT NULL, + deleted_at DATETIME DEFAULT CURRENT_TIMESTAMP, + deletion_reason TEXT DEFAULT 'auto_cleanup_7days', + total_file_size INTEGER + ) + `); + console.log('✓ Deletion Log Tabelle erstellt'); + // Erstelle Indizes await this.run('CREATE INDEX IF NOT EXISTS idx_groups_group_id ON groups(group_id)'); await this.run('CREATE INDEX IF NOT EXISTS idx_groups_year ON groups(year)'); await this.run('CREATE INDEX IF NOT EXISTS idx_groups_upload_date ON groups(upload_date)'); + await this.run('CREATE INDEX IF NOT EXISTS idx_groups_approved ON groups(approved)'); + await this.run('CREATE INDEX IF NOT EXISTS idx_groups_cleanup ON groups(approved, upload_date)'); await this.run('CREATE INDEX IF NOT EXISTS idx_images_group_id ON images(group_id)'); await this.run('CREATE INDEX IF NOT EXISTS idx_images_upload_order ON images(upload_order)'); + await this.run('CREATE INDEX IF NOT EXISTS idx_deletion_log_deleted_at ON deletion_log(deleted_at DESC)'); + await this.run('CREATE INDEX IF NOT EXISTS idx_deletion_log_year ON deletion_log(year)'); console.log('✓ Indizes erstellt'); // Erstelle Trigger diff --git a/docs/FEATURE_PLAN-delete-unproved-groups.md b/docs/FEATURE_PLAN-delete-unproved-groups.md index e8d39d2..f1bc796 100644 --- a/docs/FEATURE_PLAN-delete-unproved-groups.md +++ b/docs/FEATURE_PLAN-delete-unproved-groups.md @@ -354,30 +354,29 @@ export const getDeletionStatistics = async () => { ### Phase 1: Database & Schema (Aufgaben 1-2) -#### Aufgabe 1: Database Schema für approved-Spalte prüfen ✅ **BEREITS VORHANDEN** +#### Aufgabe 1: Database Schema für approved-Spalte prüfen ✅ **ABGESCHLOSSEN** - [x] ~~Migration Script erstellen~~ **NICHT NÖTIG** - approved-Spalte existiert bereits! - [x] ~~approved-Spalte zu groups-Tabelle hinzufügen~~ **BEREITS VORHANDEN** (DatabaseManager.js, Zeile 60) - [x] ~~Migration in DatabaseManager integrieren~~ **BEREITS VORHANDEN** (Zeile 67-75) -- [x] ~~Indizes erstellen~~ **Performance-Index für cleanup hinzufügen** -- [ ] Index für Cleanup-Abfragen hinzufügen: `CREATE INDEX IF NOT EXISTS idx_groups_cleanup ON groups(approved, upload_date)` +- [x] Index für Cleanup-Abfragen hinzugefügt: `idx_groups_cleanup` und `idx_groups_approved` **Akzeptanzkriterien:** - ✅ Spalte `approved` existiert bereits mit DEFAULT FALSE - ✅ Migration läuft automatisch bei jedem Server-Start (DatabaseManager.js) -- ⏳ Zusätzlicher Index für Cleanup-Performance hinzufügen +- ✅ Cleanup-Indizes hinzugefügt (approved, upload_date) - ✅ Keine Datenverluste - Bestehende Gruppen haben `approved = false` -#### Aufgabe 2: Deletion Log Tabelle erstellen -- [ ] `deletion_log` Tabelle im Schema definieren -- [ ] Indizes für schnelle Abfragen erstellen -- [ ] Migration Script erstellen -- [ ] Validierung der Tabellenstruktur +#### Aufgabe 2: Deletion Log Tabelle erstellen ✅ **ABGESCHLOSSEN** +- [x] `deletion_log` Tabelle im Schema definiert (DatabaseManager.js) +- [x] Indizes für schnelle Abfragen erstellt (`deleted_at DESC`, `year`) +- [x] Struktur ohne personenbezogene Daten +- [x] Validierung der Tabellenstruktur **Akzeptanzkriterien:** -- Tabelle enthält alle definierten Spalten -- Keine personenbezogenen Daten im Schema -- Indizes für `deleted_at` und `year` existieren -- Struktur ist optimal für Abfragen (letzte 10, alle, Statistiken) +- ✅ Tabelle enthält alle definierten Spalten (group_id, year, image_count, upload_date, deleted_at, deletion_reason, total_file_size) +- ✅ Keine personenbezogenen Daten im Schema +- ✅ Indizes für `deleted_at` und `year` existieren +- ✅ Struktur ist optimal für Abfragen (letzte 10, alle, Statistiken) ### Phase 2: Backend Core Logic (Aufgaben 3-5)