English 中文(简体)
How would you implement a revision control system for your models in your prefered db paradigm?
原标题:

I found out that RCS for models is an interesting problem to solve in the context of data persistence. They are several solution using the django ORM to achieve this django-reversion and AuditTrail each of which propose their own way to do it.

Here is the model (in django-model-like format) which 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 a date, a revision number, a comment and the user that did the modification.

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

Please post only one example of RCS models per post.

I m not asking for a complete code (maybe an explanation is enough?) but enough to see how this problem can be tackled in each db type.

问题回答

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

Why? Old revisions are lost when a database is compacted.

Compaction rewrites the database file, removing outdated document revisions and deleted documents.

CouchDB wiki - Compaction page

There are a couple possible solutions:

  1. Keep current and old revisions in the same database. Add an extra revision field to determine the difference between current and old revisions.
  2. Store old revisions in a separate database. When a new revision is added to the "current" database, the old revision document can be deleted and inserted into the "revisions" database.

Which one is best? It depends on how your data is going to be accessed. If you can query the old revisions independently from the current revisions, then storing the document in 2 different databases will give you some performance benefits.

In CouchDB this is rather straightforward. Every item in the DB has a _id and a _rev. So you don t need a separate revision number. I would probably do this then. Assign every item a systemrev number. This number would be a link to another DB record containing the date, comment and user for that revision.

Examples:

item being tracked:

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

And then create a separate revision record:

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

To me it seems pretty elegant....





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签