Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any tools for schema migration for NoSQL databases? [closed]

Tags:

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

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

like image 629
Alexander Artemenko Avatar asked Dec 25 '09 11:12

Alexander Artemenko


People also ask

Does NoSQL have migrations?

About NoSQL MigrationDatabases with strict schemas, such as relational databases, can be moved by preserving every schema development, also its data migration, in a version-based order. Schemaless databases still require thorough migration due to the inherent schema in any programming language that obtains the data.

Do NoSQL databases have schemas?

Does NoSQL have a schema? NoSQL databases do not have a schema in the same rigid way that relational databases have a schema. Each of the four main types of NoSQL database has an underlying structure that is used to store the data.

Can you migrate from NoSQL to SQL?

At Egnyte we use multiple databases -- SQL as well as NoSQL -- for different use cases. SQL databases can range from single-user to multi-user, while different NoSQL databases are used for different durability requirements.


2 Answers

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.

  • 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;)
like image 199
Vitaly Kushner Avatar answered Oct 18 '22 20:10

Vitaly Kushner


One of the supposed benefits of these databases is that they are schemaless, and therefore don't need schema migration tools. Instead, you write your data handling code to deal with the variety of data stored in the db.

like image 34
Ned Batchelder Avatar answered Oct 18 '22 20:10

Ned Batchelder