I’m trying to implement a feature in my LiveView app that shows “activity” for that record such as changes and comments. Ideally, any changes will show the before/after values in an easy-to-read format, similar to git commit changes. Here’s an example from Airtable:
I’m wondering if there are any libraries that can help me with this, or if it’s something I’ll have to tackle all from scratch? There are quite a lot of models in my app that I need this form of paper-trail tracking implemented for, so just doing it as a feature per model seems like a bad approach.
Assuming you’re using Ecto to manage your data schemas, you could utilize a library like ecto_diff to determine the differences between ecto structs, then build a simple model to record the lifecycle changes.
The thing about using paper_trail is that if you have a mixture of PKs that are integers and uuids, you need two version tables to track them. It’s best to pick one format and stick with it and pray you never change.
I haven’t tried it with tracking compound pk entities, but I suspect it is also problematic.
Paper trail seems interesting, I’m not sure that I necessarily need to keep every historical version of every record. I’m thinking maybe I can just make a Ecto Repo that has Repo.insert() and Repo.update() insert “changes” into the database in a transaction