@Job_Isabai regarding our conversation earlier this week about deleting historical reports from a test instance, I have put together this NodeJS script that should at least provide a starting point to work from. Currently to run the script (with NodeJS
18+), you must supply a
COUCH_URL environment variable that points to your CHT instance (ending with
/medic) and includes an admin username and password.
COUCH_URL=https://medic:email@example.com/medic node purge_docs_from_server.js
The script will prompt you to enter a date. All reports on the instance with a
reported_date at or below the given date will be completely removed from the server.
- Should NEVER be used anywhere close to a prod instance. It is intended to cause data loss!
- Totally removes the data from the server using the Couch
_purgeendpoint. There is no way to roll back these changes or recover the deleted data.
- Will only remove reports (docs where
type = data_record). No contact docs or other docs will be affected.
- Requires NodeJS
- Documents are totally removed from the server, but this deletion will NOT be replicated to any clients. The documents will remain on the client.
- For a test instance with a small set of client devices the easiest thing to do is to just reset and re-sync all the devices after running this script to ensure the devices only contain the data remaining on the server.
- Alternatively, you can implement a CHT Purging strategy that will purge all reports from client devices after a specified period of time. Then, use this script to hard-delete these purged docs from the server.
- This script is presented as-is with no guarantees of success. Use at your own risk!