How do I save history (like VCS) to CouchDB, BigCouch, or other open source database?

I'm looking for a way to use CouchDB or BigCouch (or some other "compatible" DB) in such a way that the entire changelog can be maintained, or at least archived. I know CouchDB internally does this anyway and only removes old versions after compacting. Since CouchDB / BigCouch is open source, I would guess that one could hack something together to enable this feature. For example, copying each revision to the archive database before the compacting process deletes them.

As an aside: I worked for a couple of companies that wanted an "audit history" of their SQL database, and we did that by creating an "audit table" and we created triggers that would insert records into that table on any other table when changed.

Can anyone with a lot of CouchDB knowledge tell me how this can be done? I'm curious if anyone has done this before. It looks like it would be a very useful feature, so if this hasn't been done before, I'm wondering why?

NOTE. This question is partially inspired by Dataomic, DB which has the desired properties. So I'm looking mostly for an open source version, perhaps a lighter alternative to Datomic.

+3


source to share


1 answer


I never like the idea of ​​using internal versioning for history. To me this is just a requirement to maintain the functionality of the finite sequence.

If I needed to preserve history, I would look at the linked docs approach where the link is update. This way you can support features like:

  • create two or more new documents based on the same parent.
  • create one merged document with two or more parents.

To support features like deletions, I would have a "deleted document" that I would point to the documents that are being deleted.



New documents will get a unique ID (I use the uuid function from couchdb for this), so I have a complete list of free roots.

I find the graph database useful for this, but you can just post parent links. I have something like this in the docs:

[some other content],
parent_nodes: [ list_of_parent_uuids], # these are the direct ancestors so you can build a graph.
origin_nodes: [ list of_origin_uuids] # these are the new_node uuids that the original documenst have. so you can build a view of all inheriting docs.

      

0


source







All Articles