larshei

larshei

Database Layout for an audit log?

Yesterday, I built a small Audig Log functionality to record changes to a graph database.

My initial approach was to have two separate tables, an audit_nodes that records all changes to nodes in the graph and an audit_relations that records changes to edges in the graph.

I wonder if that is a reasonable layout.

My thought was to separate the two because

  1. only the relation audit entry needs 2 nodes and the string-field relation and
  2. only the node audit entry needs a single node and a map-field data, which contains the changed attributes.

Now, to answer some questions, that is a bit hard to properly query (Or maybe it is not hard to query, but I just don’t know better :stuck_out_tongue: ), for example:

  1. List the last n changes made by a given user or
  2. List the last n changes that affected a given node

I wonder if it would be reasonable to just have one table for both, with some columns being unused for each typem and have a separate changeset for a node and edge changes.

Or even have an additional table that records when the change was made, by whom and what nodes were affected, then relate to the more specific entries (seems a bit complex?).

Have you built anything like this before?
What worked well, what did not?
What do you think is a reasonable approach?

Most Liked

dimitarvp

dimitarvp

I’d for the good old reliable:

  • Record ID
  • Record type / table
  • User ID of who did the change
  • OPTIONAL: a field capturing the changes

Not sure how would this handle related entities though, because these relations might change after the fact and if you cache them in the table that info might not be relevant anymore at some point.

These 3-4 fields should get you 90% the way there IMO.

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement