north_celt

north_celt

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.

Showing Posts 1 to 8

evadne

evadne

The most righteous solution, if you are using Postgres, would be to implement a trigger function which writes the changes to a separate table.

Otherwise you would be at the mercy of the application code actually logging 100% of the time.

north_celt

north_celt OP

Well, obviously I’m not much for being righteous because I’m using SQLite for storage on this app (for a lot of other very good reasons) :sweat_smile:

khedaywi

khedaywi

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.

hst337

hst337

You can use something like

old_words = String.split(old_text)
new_words = String.split(new_text)
diff = List.myers_difference(old_words, new_words)
greven

greven

There is also paper_trail. :slight_smile:

warmwaffles

warmwaffles

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.

north_celt

north_celt OP

Thanks, and then I’d just wrap each context that needs a diff with a transaction that saved both the diff and the model?

north_celt

north_celt OP

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
perzanko
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews