Closed colinxfleming closed 2 years ago
@elimbaum would love for you to work on this next when you get headroom
some questions:
destroy
or delete
? delete
was giving me errors, assuming this is because it doesn't also delete related objects, whereas destroy
does. just want to confirm this is ok.Not totally sure how to best test this. In paper_trail_version_test.rb
I try to manually set a version to be really old, but the change seems to not be picked up, so nothing is deleted...
Run with destroy
. The difference iirc is that delete doesn't fire callbacks but destroy does; PaperTrailVersion shouldn't have any dependent objects or trigger any callbacks. You also might be able to use destroy_all to nuke the whole set.
Also, created a year ago please! But tbh they should be the same for everything, I generally think of these as immutable.
For testing, you might want to try out timecop. I forget the exact syntax but probably something like:
with_versioning do
Timecop.freeze('2001-01-01') do
Patient.create ...
end
end
PaperTrailVersion.first # should have a created at / mod at on 2001-01-01 at midnight, I think
timecop! cool! that would also explain why i wasn't able to manually modify PaperTrail at attributes. I'll give this a go!
Thanks for creating an issue! Please fill out this form so we can be sure to have all the information we need, and to minimize back and forth.
While doing something unrelated in db I noticed that we have a bunch of spare ~Audit Trail~ PaperTrailVersion objects hanging out, including from patients that have been archived or deleted. We should remove these, since we don't need them after patient archive.
Keeping db memory usage down (AuditTrails take up almost half of our db usage). This will let us not
Here's what I'd suggest:
On
ArchivedPatient#convert_patient
, destroy all audit trail objs associated with a given patient as part of that processIn the
nightly_cleanup
task, establish a safety net by deleting any audit trail obj older than a year.Anything else?
nope!