mongoose-data-migrate

Data migration framework for node.js using mongoose

Showing:

Popularity

Downloads/wk

10

GitHub Stars

10

Maintenance

Last Commit

3yrs ago

Contributors

6

Package

Dependencies

5

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

mongoose-data-migrate

Mongodb data migration tool using node.js and mongoose. Heavily inspired by madhums/mongoose-migrate.

At a high level, here's how you use it:

  1. run 'mongoose-data-migrate create my-migration1' to create your migration files. The files are created in the migrations folder in the root of your project.
  2. implement the up and down methods in each migration file.
  3. running 'mongoose-data-migrate up' will run all migration files that are in the migrations folder that have not yet been run.
  4. running 'mongoose-data-migrate down' will execute the down method on all migration to the point that the previous 'migrate up' was run.

Installation

$ npm install -g mongoose-data-migrate
    

Usage

Usage: mongoose-data-migrate [up|down|create] 

Commands:

   up               run all new migrations since the previous run
   down             migrate down to the point of the previous migrate up
   create [title]   create a new migration file with optional [title]

Config file

mongoose-data-migrate will store the current state of migrations in a collection in mongodb. Therefore, a config file is required in order to provide the connection details to the mongodb instance.

Place the config file in the root of your project as ./config/migrations.js

The config file format is:

module.exports = {

    // The location of the the mongoose module. Since mongoose-data-migrate
    // needs to make a connection to mongodb, if you point to it here you'll
    // be able to use the same connection in your migration files rather than
    // creating your own connection.
    mongoose: '../node_modules/mongoose',

    // mongodb connection string in mongoose format: 'mongodb://username:password@host:port/database?options...'
    // See: http://mongoosejs.com/docs/connections.html
    db: 'mongodb://localhost:27017',

    // mongodb connection options in mongoose format (optional): 'mongodb://username:password@host:port/database?options...'
    // See: http://mongoosejs.com/docs/connections.html
    dbOptions: {},

    // Name for the migrations collection (defaults to 'migrations')
    collection: 'migrations'
};

Mongoose Compatability

So far mongoose-data-migrate has only been tested with Mongoose 3.8.x.

Testing

In order to run the test specs you need to have:

  1. an instance of mongodb running at localhost:27017.
  2. a db named 'mongoose_data_migrate_test' without any credentials

To run the tests:

npm test

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial