Title says it all, looking fo hints/pointer/examples...
This is database-related, and off-topic. Still, as this easily eats into the code/Perl realm when being implemented, I hope I get away with it.
So fellow Perlmonks, in case anyone has tackled this before:
My database is basically one table that holds entities. Then, another table holding attributes, each attribute having its own id and a field that links it to the parent entity, then 'attribute value' and so forth. EAV.
Now, coming from a "relational mindset", I've got problems wrapping my head around how to do "snapshots" of how a view (= a rendition of the entity with all its attributes displayed) of one entity looked at a certain point in time. In order to be able to rollback, to diff, to document (audit?) the history of an entry (an entity) in my db.
I think one way of implementing this is to add some tracking of revisions to the attribute table (to what revision an attribute belongs). Roughly, what I can think of is:
- Add a revision field to attributes table, start counting at rev. one. On SELECT, constraint to only attributes having a certain revision (latest/specific rev.); when new attributes are added, all current/unchanged attribs get copied with incremented rev number plus the new attribute. CONS: code overhead in implementation, bloat in the attributes db; or ...
- Add two revision fields, revision_start, revision_end. On SELECT, constraint to attributes that are a superset range of the desired revision. When new attributes are added, the revision_end field on attributes that remain attached to the entity is incremented. CONS: even describing it is verbose, code probably a nightmare. PRO: no bloat in attributes.
When I want to track who created/updated/deleted an attribute, I think I have to add yet another table, a journal, to match attribute revisions with users - right?
Probably I'm overseeing a very simple approach, so please, somebody shed some light.
(I've already found
these ruby gems (ehem...) with many implementations of versioning of so called Active Records. Is there something to be learned there? Is one of these implementations a good example of how to do it? ...do it well?)