Skip to content

Add general-purpose script for deleting dangling data values#583

Closed
Ramon-Jimenez wants to merge 1 commit intodevelopmentfrom
fix/general-dangling-data-cleanup
Closed

Add general-purpose script for deleting dangling data values#583
Ramon-Jimenez wants to merge 1 commit intodevelopmentfrom
fix/general-dangling-data-cleanup

Conversation

@Ramon-Jimenez
Copy link
Copy Markdown
Contributor

Summary

  • Adds a new delete-dangling-data-values.ts script that replaces the old delete-wrong-data-values.ts, which was hardcoded to a specific DHIS2 instance and COVID-specific category combos.
  • Reuses the existing ProjectDb.getDanglingDataValues() detection logic, which identifies data values whose (dataElement, categoryOptionCombo) pair no longer matches the project's current configuration.
  • Works across all projects or a specific one via --project=ID.
  • Two-step workflow: --generate writes a report + delete payload for review, --post executes the deletion.

Usage

# Step 1: Generate report (dry run)
yarn ts-node src/scripts/delete-dangling-data-values.ts --url=https://dhis2-instance.org --generate

# Or for a specific project:
yarn ts-node src/scripts/delete-dangling-data-values.ts --url=https://dhis2-instance.org --generate --project=PROJECT_ID

# Step 2: Review the generated files in src/scripts/data/
#   - dangling-data-values-report.json (human-readable)
#   - dangling-data-values-to-delete.json (DHIS2 delete payload)

# Step 3: Delete after review
yarn ts-node src/scripts/delete-dangling-data-values.ts --url=https://dhis2-instance.org --post

Context

A client reported that after removing and re-adding an indicator from a project, "dangling" data values remained in the DHIS2 database. These orphaned values were still visible in their Tableau extracts from the DHIS2 PostgreSQL. The app already detects and notifies about dangling data (via ProjectNotification), but had no general-purpose tool to clean them up.

Test plan

  • Type-checks cleanly
  • All existing tests pass (47/47)
  • Run --generate against a test DHIS2 instance and verify the report is accurate
  • Run --post and verify dangling values are removed from DHIS2

🤖 Generated with Claude Code

Replaces the old delete-wrong-data-values.ts script which was hardcoded
to a specific instance and COVID-specific category combos.

The new script reuses ProjectDb.getDanglingDataValues() to detect
orphaned data values across all projects (or a specific one), writes
a review report, and allows deletion via the DHIS2 API.

Usage:
  yarn ts-node src/scripts/delete-dangling-data-values.ts \
    --url=DHIS2URL --generate [--project=ID]
  yarn ts-node src/scripts/delete-dangling-data-values.ts \
    --url=DHIS2URL --post

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bundlemon
Copy link
Copy Markdown

bundlemon Bot commented Apr 16, 2026

BundleMon

No change in files bundle size

Unchanged groups (1)
Status Path Size Limits
Build Folder
./**/*
5.5MB +20%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

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