Closed issue #8 and reworked the docker-compose and also made a command to clear the db which should run once a night at 00:00. it deletes all entries that are older then 40 days
This commit is contained in:
@@ -2,6 +2,8 @@ package db_management
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
@@ -90,3 +92,18 @@ func GetTopUsers(limit int) []UserStats {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func CleanupOldEntries() {
|
||||
query := `DELETE FROM voice_sessions WHERE created_at < datetime('now', '-40 days)`
|
||||
|
||||
result, err := DB.Exec(query)
|
||||
if err != nil {
|
||||
log.Printf("Fehler beim DB-Cleanup: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
if rowsAffected > 0 {
|
||||
log.Printf("DB Cleanup erfolgreich: %d alte Einträge gelöscht.", rowsAffected)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user