Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node-mongo-native migration framework

I'm working on a node.js server, and using MongoDB with node-mongo-native. I'm looking for a db migration framework, similar to Rails migrations. Any recommendations?

like image 356
yotam.shacham Avatar asked Jul 10 '12 21:07

yotam.shacham


2 Answers

I'm not aware of a specific native Node.js tool for doing MongoDB migrations .. but you do have the option of using tools written in other languages (for example, Mongoid Rails Migrations).

It's worth noting that the approach to Schema design and data modelling in MongoDB is different from relational databases. In particular, there is no requirement for a collection to have a consistent or predeclared schema so many of the traditional migration actions such as adding and removing columns are not required.

However .. migrations which involve data transformations can still be useful.

If your application is expecting data to be in a certain format (eg. you want to split a "name" field into "first name" and "last name") there are several strategies you could use if the idea of using migration tools written in another programming language isn't appealing:

  • handle data differences in your application logic, so old and new data formats are both acceptable (perhaps "upgrading" records to match a newer format as they are updated)
  • write a script to do a once off data migration
  • contribute MongoDB helpers to node-migrate
like image 54
Stennie Avatar answered Oct 07 '22 00:10

Stennie


I've just finished writing a basic migration framework based on node-mongo-native: https://github.com/afloyd/mongo-migrate. It will allow you to migrate up & down, as well as migrating up/down to a specific revision number. It was initially based on node-migrate, but obviously needed to be changed a bit to make it work.

The revision history is stored in mongodb and not on the file system like node-migrate, allowing collaboration on the same project using a single database. Otherwise each developer running migrations could cause migrations to run more than once against a database.

The migrations themselves are file-based, also helping with collaboration on a single project where each developer is (or is not) not using the same database. So when each dev runs the migration, all migration files not already run against his/her database will be run.

Check out the documentation for more info.

like image 45
Austin Floyd Avatar answered Oct 06 '22 23:10

Austin Floyd