django-pghistory icon indicating copy to clipboard operation
django-pghistory copied to clipboard

Events consolidated into single table?

Open rrauenza opened this issue 4 years ago • 3 comments

I'd like to replace my current auditing system, and have been studying your code tonight. In order to change to this package I really need a way to query a single table with ordered events by time.

I've tried figuring out a way to change the Events base class to not be abstract... no success, and it would involve table inheritance. Maybe an external table with content types that point to the actual tables?

Do you have any suggestions as to how this could be done without modifying pghistory?

rrauenza avatar Dec 15 '20 18:12 rrauenza

I think I've found a way to leverage pghistory and its Context model and middleware and make my own trigger on each audited table to insert into my own Events table, storing NEW and OLD as JSONB's....

rrauenza avatar Dec 17 '20 08:12 rrauenza

Does this fit your use case?

https://django-pghistory.readthedocs.io/en/latest/extras.html#aggregating-events-with-aggregateevent

radusuciu avatar Feb 08 '22 20:02 radusuciu

@rrauenza yea the aggregate event model as pointed out above should allow you to consolidate events.

It sounds like what you are wanting to do might be a little less structured if you're talking about JSONB fields though. Do you want to be able to store historical changes that relate to the schema at that point in time? Currently pghistory doesn't support this use case, but I am considering it in a later iteration of this library.

I'm going to keep this open as an enhancement for now since I'm planning on finding a way to allow JSONBs to be tracked. Will report back when it's officially slated to be integrated

wesleykendall avatar Sep 06 '22 00:09 wesleykendall