Skip to content

Feat/421 wipe events table script#450

Open
Priyanshubhartistm wants to merge 5 commits intocameri:mainfrom
Priyanshubhartistm:feat/421-wipe-events-table-script
Open

Feat/421 wipe events table script#450
Priyanshubhartistm wants to merge 5 commits intocameri:mainfrom
Priyanshubhartistm:feat/421-wipe-events-table-script

Conversation

@Priyanshubhartistm
Copy link
Copy Markdown
Contributor

@Priyanshubhartistm Priyanshubhartistm commented Apr 10, 2026

Description

  • Added a new clean-db CLI utility for safe events table cleanup.
  • Added npm script support with npm run clean-db.
  • Added safety guardrails:
    • Explicit confirmation prompt requiring Type DELETE to confirm.
    • --force option to skip prompt.
    • Extra warning when NODE_ENV is production.
  • Added purge options:
    • --all for full wipe.
    • --older-than=days for timestamp-based cleanup.
    • --kinds=1,7,4 for kind-specific cleanup.
    • --dry-run to show affected row count without deleting.
  • Added PostgreSQL-specific behavior:
    • Full wipe uses TRUNCATE TABLE events, event_tags RESTART IDENTITY CASCADE.
    • Selective delete runs VACUUM ANALYZE events afterward.
  • Added unit tests for clean-db option parsing and validation.
  • Updated README with relay maintenance usage examples.

Related Issue

Closes #421
#421

Motivation and Context

Relay operators need a safe and repeatable way to reset or prune heavy event data during testing and maintenance without running manual SQL commands.

This change improves:

  • Safety with explicit confirmation and force control.
  • Flexibility with multiple cleanup modes.
  • Speed with optimized full-wipe behavior.
  • Clear maintenance documentation.

How Has This Been Tested?

  • npm run lint
  • npm run build
  • npm run test:unit
  • Manual end-to-end verification on a disposable local PostgreSQL instance:
    • Seeded sample events with different kinds and ages.
    • Verified dry-run counts before deletes.
    • Ran selective cleanup and confirmed post-delete dry-run showed zero.
    • Ran full wipe and confirmed post-wipe dry-run showed zero.
    • Verified final database counts were events=0 and event_tags=0.

Screenshots (if appropriate):

N/A (CLI and database maintenance change)

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • All new and existing tests passed.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new administrative CLI (npm run clean-db) to safely wipe or selectively prune relay event data, aimed at helping operators maintain/test relays without manual SQL.

Changes:

  • Introduces src/clean-db.ts CLI with confirmation/--force, --dry-run, and filter options (--all, --older-than, --kinds), plus Postgres optimizations (TRUNCATE / VACUUM ANALYZE).
  • Adds unit tests for option parsing/validation.
  • Documents relay maintenance usage in README and exposes the CLI via a new npm script.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/clean-db.ts Implements the clean-db CLI, option parsing, confirmation flow, and DB operations (TRUNCATE / DELETE + VACUUM).
test/unit/clean-db.spec.ts Adds unit tests for option parsing/validation behavior and error messaging.
README.md Adds “Relay Maintenance” section with clean-db usage examples.
package.json Adds clean-db npm script entry point.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/clean-db.ts Outdated
Comment thread README.md Outdated
Comment thread src/clean-db.ts Outdated
@Priyanshubhartistm
Copy link
Copy Markdown
Contributor Author

@cameri
could you please review,whenever you free
thanku

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Wipe events table script

2 participants