Git Product home page Git Product logo

mongo-migrate's Introduction

MongoDB migrate

This project aims to be an agnostic migration system for mongodb. Sometimes when you add attributes, you need to give a value for existing documents. Doing this frequently, this tool can help, since it has an straightforward syntax and simplicity.

Dependencies

MongoDB client - the bin file that comes with mongodb. I will soon create an installation script to make things easier. For now you need to download it from mongodb website. - http://www.mongodb.org/downloads

Instalation

$ git clone git://github.com/emerleite/mongo-migrate.git
$ cd mongo-migrate
$ cp config-sample.cfg config.cfg

Edit config.cfg with your database information

Basic information

By convention, mongo migrate uses the directory db/migrate when generating and running migrations. You can change it, by editing the MIGRATION_DIR configuration at config.cfg. See config.sample.cfg for details.

Configuration

MongoDB migrate uses a configuration file called config.cfg. It has the following options:

  • MONGO_HOST - The database host. Default is localhost
  • MONGO_DATABASE - Required. Do not have default value
  • MIGRATION_DIR - Where to find migrations. Default is ./db/migrate/
  • MONGO_USR - Username. Default is empty
  • MONGO_PWD - Password. Default is empty

Note: When you use MONGO_USR and not MONGO_PWD you'll be prompted for password.

Usage

Mongo migrate has two modes. generate and run. The syntax is pretty straitforward as explained above:

Generate

Mongo migrate generates migrtion in the following format:

YYYMMDDhhmmssmm_name.js. Ex: 20111209002426_add_person.js

$ ./mongo_migrate -gf [migration_name]

This will generate the following file:

var migration = {
  up: function() {
  
  },
  down: function() {

  }
};

migration[target].call();

Put the code for the changes on up and the code for rollback on down.

Running

Mongo migrate has 2 modes of running. Up and Down. The first make things happen and the second is a rollback. For these 2 modes, we call run one specific migration or all migrations. Mongo migrate controll the current migration, to enable run only the last migrations or just run all.

Options

-g generate -r run -t target (up|down) -f file_name -c configuration file

One migration

$ ./mongo_migrate -rt up   -f [file_name]
$ ./mongo_migrate -rt down -f [file_name]

The name can bem the full name or partial name. Ex: 20111209002426_add_person.js or only add_person. Mongo migrate will first look for a full name and after will fallback to find the file based on the partial name.

All migrations

$ ./mongo_migrate -rt up
$ ./mongo_migrate -rt down

Configuration file

If you want to pass the configuration file path and not use the convention (i.e ./config.cfg), just use the -c option parameter:

$ ./mongo_migrate -rt up -f migration_file -c /path/to/config/file
$ ./mongo_migrate -rt down -c /path/to/config/file
$ ./mongo_migrate -gf migration_name -c /path/to/config/file

When running all migrations, mongo migrate will run only the new migrations, because it controls witch is the last one.

To-Do

Author

License:

(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.