Feat/421 wipe events table script#450
Feat/421 wipe events table script#450Priyanshubhartistm wants to merge 4 commits intocameri:mainfrom
Conversation
There was a problem hiding this comment.
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.tsCLI 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.
| if (arg.startsWith('--older-than')) { | ||
| const [value, nextIndex] = getOptionValue(arg, args, index) | ||
| options.olderThanDays = parseOlderThanDays(value) | ||
| index = nextIndex | ||
| continue | ||
| } | ||
|
|
||
| if (arg.startsWith('--kinds')) { | ||
| const [value, nextIndex] = getOptionValue(arg, args, index) | ||
| options.kinds = parseKinds(value) | ||
| index = nextIndex | ||
| continue | ||
| } |
There was a problem hiding this comment.
parseCleanDbOptions matches --older-than / --kinds using startsWith, which means options like --older-than-days or --kinds-extra will be treated as valid and parsed instead of raising Unknown option. Tighten the check to only accept the exact flag (--older-than/--kinds) or an inline-value form (--older-than=/--kinds=).
|
|
||
| ## Relay Maintenance | ||
|
|
||
| Use `clean-db` to wipe or prune only the `events` table data. |
There was a problem hiding this comment.
The README says clean-db wipes/prunes "only the events table data", but the implementation also removes data from the derived event_tags table (TRUNCATE includes it when present, and selective deletes trigger cleanup). Please clarify the docs to mention event_tags is also affected so operators don’t assume tags remain intact.
| Use `clean-db` to wipe or prune only the `events` table data. | |
| Use `clean-db` to wipe or prune `events` table data. This also removes corresponding data from the derived `event_tags` table when present. |
|
|
||
| if (options.all) { | ||
| await runAllDelete(dbClient) | ||
| console.log('Deleted all events with TRUNCATE.') |
There was a problem hiding this comment.
When --all is used and event_tags exists, runAllDelete truncates both events and event_tags, but the user-facing message says "Deleted all events with TRUNCATE." Consider updating the output to reflect both tables (or otherwise make the scope explicit) to avoid misleading operators.
| console.log('Deleted all events with TRUNCATE.') | |
| console.log('Deleted all rows from events and event_tags with TRUNCATE.') |
Description
npm run clean-db.Type DELETEto confirm.--forceoption to skip prompt.NODE_ENVis production.--allfor full wipe.--older-than=daysfor timestamp-based cleanup.--kinds=1,7,4for kind-specific cleanup.--dry-runto show affected row count without deleting.TRUNCATE TABLE events, event_tags RESTART IDENTITY CASCADE.VACUUM ANALYZE eventsafterward.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:
How Has This Been Tested?
npm run lintnpm run buildnpm run test:unitevents=0andevent_tags=0.Screenshots (if appropriate):
N/A (CLI and database maintenance change)
Types of changes
Checklist: