Object History Implementation?

I’m just thinking out loud here. I’d like to have the ability to store historical versions of each vertex and edge created from my domain model. I wondering how I might like to do it. At this point, I am more concerned with it being easy to use and reason about than I am with it being the most efficient implementation possible.

Use cases for this sort of functionality include being able to provide diffs showing changes, establishing audit trails, etc…

One possibility would be to create a mirror class for every class in the domain, e.g. a Person class with properties name and age would require a Person_historical class with the same properties + a property that indicating the @rid for the Person that is was a historical version of. Every time a Person vertex changed you would instantiate a Person_historical where the properties of the values where what the Person was before applying any updates. This is somewhat like the way we currently do things with RDBMS.

Another possibility that has occurred to me is that each vertex could essentially be connected to a chain of historical versions of itself. I think I’d create an Edge class with a property that captured the time that the change occurred and maybe another property to indicate whether the change was a deletion or an update (or something else?). So, a save of a Person would result in the creation of an additional person that was inserted between the itself and any existing historical versions of itself. *edit – This is not a great idea. The historical versions need to be some different class. Otherwise, SELECT * FROM Foo would result in a mixture of results that represent both the current state of the application and the historical state.

Anyway, I was just wondering if anyone had done anything like this before with OrientDB (or any graph database). Maybe one of my ideas is a good place to begin? Maybe there is some existing functionality that I’m not yet aware of that I should take into account? Maybe there is a totally different and better way to do this?

1 Like

Hi, I am struggling with the same problem. I will probably use that each vertex that needs history will extend abstract History class that has one filed called modLog. This field will be a list of all modifications on that instance. This is document approach. For example:

Person extends History {
name: 'Marco',
lastName: 'Polo'
modLog: [
    type: 'created',
    userId: '#14:22',
    timestamp: '2019-07-02 12:00:00'
    type: 'updated',
    userId: '#2:28',
    timestamp: '2019-07-09 18:45:00',
    fields: [{
       field: 'name',
       oldValue: 'Marko',
       newValue: 'Marco'

I didn’t make it, this is just my idea how I am going to solve this problem. This is for my only analytical data, so I do not need crazy reports on this.