Skip to content

Add dataset deletion cascade and scheduled cleanup #120

Closed

Description

@neuromechanist

Problem

When datasets are deleted externally (GitHub repo removed, S3 data cleaned up), the D1 database records are not cleaned up. This causes:

  • Stale dataset records in the datasets table
  • id_sequence counter gets out of sync (e.g. nm jumps from 107 to 153)
  • Orphaned records in publication_requests, dataset_versions, dataset_collaborators

This was discovered when 7 stale nm datasets and 23 xx sandbox datasets remained in D1 after their repos were deleted. Manual cleanup was required.

Requirements

1. Admin dataset delete command

  • DELETE /admin/datasets/:id backend endpoint (admin-only)
  • Cascade cleanup: datasets, publication_requests, dataset_versions, dataset_collaborators
  • Optional GitHub repo deletion (via new deleteRepository() in github.ts)
  • Optional S3 data cleanup (skip for Object Lock datasets with DOIs)
  • Audit log entry for deletion
  • nemar admin delete-dataset <id> CLI command with confirmation prompt

2. Scheduled cleanup (Cloudflare Workers cron)

  • Stale nm datasets: auto-delete after 90 days of inactivity (no uploads, no PRs, no version changes)
  • Sandbox xx datasets: auto-reset after 2 weeks
  • Add cron trigger to wrangler.toml: [triggers] crons = ["0 3 * * *"]
  • Implement scheduled event handler in backend/src/index.ts
  • Email notification before deletion (e.g. 7-day warning)

3. Missing infrastructure (identified during exploration)

  • No deleteRepository() function in backend/src/services/github.ts
  • No S3 batch delete function in backend/src/services/s3.ts
  • No cron triggers configured in wrangler.toml
  • No last_activity_at column on datasets table for staleness detection
  • id_sequence not decremented on deletion (may need recalculation logic)

4. Safety considerations

  • Published datasets with DOIs: S3 Object Lock (GOVERNANCE mode, 100-year retention) prevents data deletion. Must archive instead of delete, or release lock explicitly.
  • Must not delete datasets with active publication requests
  • Decrement or recalculate id_sequence to avoid ID gaps
  • Dry-run mode for scheduled cleanup before enabling auto-delete

Related

Activity

  1. added a commit that references this issue on Feb 12, 2026
    ed557bb
  2. neuromechanist commented on Feb 12, 2026

    @neuromechanist
    ContributorAuthor

    Completed in PR #131 (merged to epic branch)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions