As a part of @vikrantwiz02’s work to support bulk-deleting contacts and their hierarchy+reports we are leveraging the new archiving functionality that copies all the “archived” docs to a new medic-archive DB and them purges all trace of the docs from the medic db.
I want to continue a discussion here that @diana and I started on the archiving PR regarding how the data is going to look downstream in Postgres for deployments running cht-sync.
As things stand now, when you archive a doc, downstream in Postgres nothing happens. The data stays in place and no new changes will ever show up for those records (since the source doc is no longer in the medic db). This is different from when a doc is _deleted in medic which, as I understand it, actually causes the record to be removed in Postgres.
The problem:
The original thinking behind leveraging archiving when doing the bulk-contact-delete was that it offered a bit of safety from unintentional data-loss because the contact/report data still exists in medic-archive and could be recovered if necessary. However, it feels wrong to still see bulk-deleted contacts in Postgres. Just semantically that feels unexpected and most of the time when you are deleting a contact, it is because it is invalid and/or you do not want to track data for it at all any more.
The current options I see for how to proceed are:
- Leave it as is (deleted contacts/reports stay in Postgres).
- Update the bulk-delete code to
_deletethe docs instead of archiving - unfortunately, this makes deletes irreversible (you can pass the--dry-runparam to at least check the blast radius first, but…). - Do something to the doc in
medicbefore it is archived that cht-sync can interpret so it knows the contact is gone.- Maybe we could
_deletethe doc before archiving it? If we just do this I am afraid we end up with an essentially empty doc inmedic-archive, right? - Maybe we could have a custom “archive” flow that sends the doc to
medic-archive, then_deletes it, then purges it. So, the last change in the changelog for the doc will be the delete and Postgres can drop the record.
- Maybe we could