Skip to content

Add dataset deletion cascade and scheduled cleanup (#120) - #131

Closed
neuromechanist wants to merge 3 commits into
feature/issue-128-epic-deletionfrom
feature/issue-120-deletion-cascade
Closed

neuromechanist wants to merge 3 commits into
feature/issue-128-epic-deletionfrom
feature/issue-120-deletion-cascade

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Phase 3 of deletion epic (#128). Builds on Phase 1 (S3 deletion, #129) and Phase 2 (GitHub deletion, #130) to provide full cascade deletion.

  • DELETE /admin/datasets/:id backend route with role-based permission checks
  • nemar admin delete-dataset <id> CLI command with confirmation and summary
  • Shared deleteDatasetCascade service for reuse by cron and admin route
  • Cloudflare Workers scheduled cron (daily 3 AM UTC) for sandbox and stale dataset cleanup
  • Migration 0011: last_activity_at column for staleness detection

Permission model

  • Published datasets (with DOI): only owner can delete, requires force=true
  • Unpublished datasets: admin or owner can delete
  • Active publication requests block deletion (409)

Cascade steps

  1. Delete GitHub repo (idempotent)
  2. Delete S3 objects (skip for published if not forced)
  3. Delete D1: dataset_versions, publication_requests, datasets (cascades collaborators)
  4. Audit log entry

Scheduled cleanup

  • Sandbox (xx) datasets: auto-delete after 14 days
  • Stale nm datasets: unpublished, no DOI, 90 days inactive

Test plan

  • Backend typecheck passes
  • CLI typecheck passes
  • Lint clean (biome)
  • Integration tests pass with API keys
  • Manual: create test dataset, delete via CLI, verify cleanup

Closes #120

- DELETE /admin/datasets/:id backend route with permission checks
  - Published datasets (with DOI): owner-only, requires force=true
  - Unpublished datasets: admin or owner
  - Blocks deletion if active publication requests exist
- Shared deletion service (backend/src/services/deletion.ts)
  - Cascade: GitHub repo, S3 objects, D1 records
  - Partial failure tracking with step-by-step results
- CLI command: nemar admin delete-dataset <id> [--force]
  - Confirmation prompt, DOI warning, deletion summary
- Scheduled cleanup cron (daily 3 AM UTC)
  - Sandbox (xx) datasets: auto-delete after 14 days
  - Stale nm datasets: delete if unpublished, no DOI, 90 days inactive
- Migration 0011: add last_activity_at column to datasets
- Integration tests for deletion endpoint

Closes #120
@github-actions

github-actions Bot commented Feb 12, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR131

Version: 0.4.0-PR131.f256ebc
Commit: f256ebc


🤖 Updated on each push.

- Backfill last_activity_at in migration (prevents cron deleting old datasets)
- Use db.batch() for atomic D1 deletion (prevents partial orphans)
- Remove dead skipS3 option from admin route
- Add MAX_DELETIONS_PER_RUN limit (10) to cron handler
- deleted field now reflects all step outcomes (GitHub, S3, D1)
- Wrap cron DB queries in independent try-catch blocks
- Wrap cron and admin audit log writes in try-catch
- CLI uses spinner.warn when deletion has warnings
- Always log cron summary even when zero datasets found
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Squash-merged manually to epic branch feature/issue-128-epic-deletion

neuromechanist added a commit that referenced this pull request Feb 12, 2026
Phase 3 of epic #128: wires S3 and GitHub deletion into a full cascade.

- Add shared deleteDatasetCascade service (GitHub, S3, D1 batch delete)
- Add DELETE /admin/datasets/:id with DOI/owner permission checks
- Add admin delete-dataset CLI command with confirmation prompt
- Add scheduled cron cleanup (sandbox 14d, stale nm 90d)
- Add last_activity_at migration with backfill
- Harden error handling: all steps reflected in deleted field,
  independent try-catch for cron queries and audit log writes
@neuromechanist
neuromechanist deleted the feature/issue-120-deletion-cascade branch March 6, 2026 23:56

This branch was previously deployed

1 inactive deployment
npm — f256ebc3 Deployed Feb 12, 2026 by neuromechanist via publish #215
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.

1 participant