DARIAEngineering / dcaf_case_management

Rails-based case management system for abortion funds
MIT License
87 stars 245 forks source link

Delete history on patient archive and clean them out of db #1974

Closed colinxfleming closed 2 years ago

colinxfleming commented 4 years ago

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:

nope!

colinxfleming commented 2 years ago

@elimbaum would love for you to work on this next when you get headroom

elimbaum commented 2 years ago

some questions:

elimbaum commented 2 years ago

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...

colinxfleming commented 2 years ago

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
elimbaum commented 2 years ago

timecop! cool! that would also explain why i wasn't able to manually modify PaperTrail at attributes. I'll give this a go!