您将如何在您喜欢的数据库范例中为您的模型实现版本控制系统?
我发现模型的 RCS 是在数据持久性背景下需要解决的一个有趣的问题。它们是使用 django ORM 来实现此目的的几种解决方案 django-reversion 和 AuditTrail 每个都提出了自己的方法来做到这一点。
这是我想要进行修订的模型(采用 django-model-like 格式):
class Page(Model):
title = CharField()
content = TextField()
tags = ManyToMany(Tag)
authors = ManyToMany(Author)
- 每个修订版都应该用日期、修订号、< strong>评论和进行修改的用户。
您将如何在您喜欢的数据库(Mongo、neo4j、CouchDb、GAE 数据存储)中执行此操作?
请在每篇文章中仅发布一个 RCS 模型示例。
我并不是要求提供完整的代码(也许解释就足够了?),但足以了解如何在每种数据库类型中解决此问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,如果您使用的是 CouchDB,请不要使用 _rev 字段。
为什么?压缩数据库时,旧版本会丢失。
CouchDB wiki - 压缩页面
有几种可能的解决方案:
哪一个最好?这取决于您的数据将如何被访问。如果您可以独立于当前修订版查询旧修订版,那么将文档存储在两个不同的数据库中将为您带来一些性能优势。
First of all, if you are using CouchDB, do not use the _rev field.
Why? Old revisions are lost when a database is compacted.
CouchDB wiki - Compaction page
There are a couple possible solutions:
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.
在 CouchDB 中,这相当简单。数据库中的每个项目都有一个 _id 和一个 _rev。因此您不需要单独的修订号。那时我可能会这样做。为每个项目分配一个系统版本号。该编号将是指向另一个数据库记录的链接,其中包含该修订的日期、注释和用户。
示例:
正在跟踪的项目:
然后创建一个单独的修订记录:
对我来说,这看起来相当优雅......
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:
And then create a separate revision record:
To me it seems pretty elegant....