是否有用于NoSQL数据库的架构迁移的工具? [英] Are there any tools for schema migration for NoSQL databases?

查看:61
本文介绍了是否有用于NoSQL数据库的架构迁移的工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种自动为诸如MongoDB或CouchDB之类的数据库进行模式迁移的方法.

I'm looking a way to automate schema migration for such databases like MongoDB or CouchDB.

最好用python编写此仪器,但是其他任何语言也可以.

Preferably, this instument should be written in python, but any other language is ok.

推荐答案

由于nosql数据库可能包含大量数据,因此无法在常规rdbms语句中迁移它.实际上,一旦数据超过某个大小阈值,您就无法对rdbms执行此操作.将站点停工一天以将字段添加到现有表是不切实际的,因此使用rdbms最终会造成难看的补丁,例如仅为该字段添加新表并进行联接以获取数据. 在nosql世界中,您可以做几件事.

Since a nosql database can contain huge amounts of data you can not migrate it in the regular rdbms sence. Actually you can't do it for rdbms as well as soon as your data passes some size threshold. It is impractical to bring your site down for a day to add a field to an existing table, and so with rdbms you end up doing ugly patches like adding new tables just for the field and doing joins to get to the data. In nosql world you can do several things.

  • 正如其他人建议的那样,您可以编写代码,以便其处理可能的架构的不同版本".这通常比看起来简单.多种模式更改对于编写代码而言是微不足道的.例如,如果要向架构中添加新字段,则只需将其添加到所有新记录中,而在所有旧记录中该字段将为空(您不会收到字段不存在"错误或其他任何内容;).如果您需要旧记录中的字段的默认"值,那么在代码中就太简单了.
  • 另一个非常重要的方案更改(例如字段重命名和结构更改)实际上是唯一可行的明智选择,它是将schema_version存储在EACH记录中,并具有将数据从任何版本迁移到上的下一个版本的代码阅读.也就是说,如果您当前的架构版本为10,并且您从数据库中读取了版本为7的记录,则您的数据库层应调用migration_8,migrate_9和migration_10.这样,被访问的数据将逐渐迁移到新版本.如果没有访问它,那么谁在乎它是哪个版本;)
  • As others suggested you can write your code so that it will handle different 'versions' of the possible schema. this is usually simpler then it looks. Many kinds of schema changes are trivial to code around. for example if you want to add a new field to the schema, you just add it to all new records and it will be empty on the all old records (you will not get "field doesn't exist" errors or anything ;). if you need a 'default' value for the field in the old records it is too trivially done in code.
  • Another option and actually the only sane option going forward with non-trivial schema changes like field renames and structural changes is to store schema_version in EACH record, and to have code to migrate data from any version to the next on READ. i.e. if your current schema version is 10 and you read a record from the database with the version of 7, then your db layer should call migrate_8, migrate_9, and migrate_10. This way the data that is accessed will be gradually migrated to the new version. and if it is not accessed, then who cares which version is it;)

这篇关于是否有用于NoSQL数据库的架构迁移的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆