How would you implement a version control system for your models in your preferred db paradigm?

I found out that RCS for models is an interesting problem to solve in the context of data storage. These are several solutions that use ORM django to achieve this django-reversion and AuditTrail , each of which offers its own way to do this.

Here is the model (in django-model-like format) that I would like to have revisions:

class Page(Model): title = CharField() content = TextField() tags = ManyToMany(Tag) authors = ManyToMany(Author) 
  • Each revision should be annotated with the date , revision number , comment and the user who made the modification.

How would you do this in your preferred db (Mongo, neo4j, CouchDb, GAE Datastore)?

Please post only one example RCS model per post.

I am not asking you to enter the full code (maybe enough explanation?), But enough to understand how this problem can be solved in each type of db.

+7
sql graph-databases persistence key-value-store document-database
source share
2 answers

First of all, if you are using CouchDB, do not use the _rev field.

Why? Older versions are lost when compacting the database.

Compression overwrites the database file, deleting obsolete documents and deleted documents.

CouchDB wiki compaction page

There are several possible solutions:

  • Keep current and old versions in the same database . Add an additional revision field to determine the difference between the current and old versions.
  • Keep old versions in a separate database . When a new version is added to the "current" database, the old document can be deleted and inserted into the "revision" database.

Which one is better? It depends on how your data is available. If you can request older versions regardless of current changes, then storing the document in two different databases will give you some performance benefits.

+2
source share

In CouchDB, this is pretty simple. Each item in the database has _id and _rev. Therefore, you do not need a separate version number. Then I would do it. Assign a system number to each element. This number will be a link to another database record containing the date, comment and user for this revision.

Examples:

tracked by:

 { _id: "1231223klkj123", _rev: "4-1231223klkj123", systemRev: "192hjk8fhkj123", foo: "bar", fooarray: ["bar1", "bar2", bar3"] } 

Then create a separate entry:

 { _id: "192hjk8fhkj123", _rev: "2-192hjk8fhkj123", user: "John", comment: "What I did yesterday", date: "1/1/2010", tags: ["C# edits", "bug fixes"] } 

It seems to me pretty elegant ....

0
source share

All Articles