Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cleanup command to remove expired db entries #2035

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

bjoern-m
Copy link
Contributor

@bjoern-m bjoern-m commented Jan 28, 2025

Description

This PR adds a new cleanup command to the backend, enabling automated database cleanup for expired entities.

Implementation

  • New cleanup command:
    • Implemented using cobra CLI framework.
    • Supports dry-run mode and execution mode (--run).
    • Allows specifying individual tables to clean up (--tables flag).
  • Added cleanup logic for:
    • audit_logs: Uses a retention period from the configuration.
    • flows and webauthn_session_data: Deletes expired entries based on timestamps.
  • Configuration updates:
    • Introduced audit_log.retention in config.yaml (default: 720 hours).
    • Added validation for retention duration in config_audit_log.go.
  • Persistence layer updates:
    • Extracted FlowPersister from flowdb.go and moved it to flow_persister.go.
    • Updated AuditLogPersister to support batch deletion of expired logs.

Additionally when creating a new audit log entry, the created_at and updated_at timestamps are now in UTC.

Tests

  1. Run hanko cleanup --tables=audit_logs --run to perform a real cleanup.
  2. Run hanko cleanup without --run to simulate cleanup.
  3. Modify config.yaml to test different retention settings.

@bjoern-m bjoern-m force-pushed the feat-cleanup-command branch 2 times, most recently from b16bc20 to 1718276 Compare January 29, 2025 14:48
@bjoern-m bjoern-m force-pushed the feat-cleanup-command branch from 1718276 to ba1f9db Compare January 29, 2025 14:53
@bjoern-m bjoern-m marked this pull request as ready for review January 29, 2025 15:02
@bjoern-m bjoern-m merged commit e2d0db2 into main Feb 3, 2025
8 checks passed
@bjoern-m bjoern-m deleted the feat-cleanup-command branch February 3, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Recently closed
Development

Successfully merging this pull request may close these issues.

2 participants