Skip to content

[FEATURE] Wipe events table script #421

Closed

Description

@cameri

Describe the solution you'd like
I would like a new administrative CLI script, likely triggered via npm run clean-db, that provides a safe and structured way to wipe or prune the events table. Other tables are out of scope.

Functional Requirements:

  1. Safety First: The script must require an explicit confirmation (e.g., Type 'DELETE' to confirm) or a --force flag to prevent accidental data loss in production.
  2. Flexible Purging Options:
    • --all: Perform a full wipe of the events data.
    • --older-than=[days]: Delete events based on the created_at timestamp.
    • --kinds=[1,7,4]: Target specific Nostr event kinds for removal.
  3. PostgreSQL Optimizations:
    • For the --all flag, the script should use TRUNCATE TABLE events RESTART IDENTITY CASCADE; for near-instant execution and immediate disk space reclamation.
    • For selective deletes, the script should run VACUUM ANALYZE events; afterward to ensure the Postgres query planner is updated.
  4. Dry Run: A --dry-run flag to output the count of rows that would be affected without executing the deletion.

Describe alternatives you've considered

  • Manual SQL execution: Hard to script and maintain across different deployment environments.
  • Dropping the Database: Overkill, as it requires re-running migrations and re-configuring permissions/extensions (like pgcrypto).

Additional context

Technical Implementation Details:

  • Batching: If deleting millions of rows via --older-than, the script should ideally delete in batches to avoid bloating the WAL (Write-Ahead Log) or locking the table for an extended period. Optional.
  • Referential Integrity: Ensure that related data in auxiliary tables (like tags or deletions) is handled correctly, leveraging PostgreSQL's CASCADE or explicit sub-queries.
  • Environment Check: The script should check the NODE_ENV and provide an extra warning if it detects a production environment.

Expected Outcomes:

  • A new clean-db utility script.
  • The ability to quickly reset a relay's state during data-heavy testing.
  • Updated README.md instructions for relay maintenance.

Activity

  1. self-assigned this
    on Apr 9, 2026
  2. Priyanshubhartistm commented on Apr 9, 2026

    @Priyanshubhartistm
    Collaborator

    Hi @cameri,
    I want to work on this issue. Could you please assign it to me? 🙏
    I'm interested in implementing the wipe events table script as described.
    Thanks!

  3. YashIIT0909 commented on Apr 9, 2026

    @YashIIT0909
    Contributor

    Hi @cameri, can I work on this issue

  4. chappie-daemon commented on Apr 9, 2026

    @chappie-daemon
    Collaborator

    Hi @YashIIT0909, thanks for your interest! We're practicing fairness in issue assignment—each contributor gets one open issue at a time so everyone has a chance. You're currently working on #411. Once you've completed that, feel free to come back and we'd love to have you work on this one too! 💪

  5. Priyanshubhartistm commented on Apr 9, 2026

    @Priyanshubhartistm
    Collaborator

    Hi @phoenix-server @cameri, can I work on this issue? I’m not working on any other issue right now, so can i start

  6. cameri commented on Apr 9, 2026

    @cameri
    OwnerAuthor

    Done

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

Metadata

Metadata

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions