Reputation: 925
In have entities: Collection
and Item
. Each collection has many items. Both Collection
and Item
can be edited collaboratively by all users of the application. I have to provide a way to undo changes. Versioning Item
records is straightforward, the difficult part is to version the relation between the Collection
and Item
.
How to model this in a relational database?
I have been thinking about using a multi-valued Temporal Property. Beside Collection
and Item
there is a link table with vt_from
and vt_to
time stamps. Probably I would have to create also a CollectionVersion
entity, also with vt_from
and vt_to
attributes. Those versions would be listed on the "history" page of the collection. However, I haven't came up yet with a general algorithm for reverting changes. Maybe I should have diff lists (added/removed) connected to the CollectionVersion
that would be used for that purpose?
Upvotes: 2
Views: 219
Reputation: 3093
What you are describing should be easy to model using event sourcing. Basically you want to store the changes to the collection as entities. The actual collections state at anytime can be calculated by applying the collection of events associated with it from creation to the desired point in time.
http://martinfowler.com/eaaDev/EventSourcing.html
http://codebetter.com/blogs/gregyoung/archive/2010/02/20/why-use-event-sourcing.aspx
Upvotes: 1