Giter Club home page Giter Club 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 a 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 straightforward as explained above:

Generate

Mongo migrate generates migration 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 controls 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 be 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 which 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.

mongo-migrate's People

Contributors

anasser avatar emerleite avatar mkantor avatar qmx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongo-migrate's Issues

bc: command not found

When I try to run mongo migrate I have this output:
line 122: bc: command not found
line 128: bc: command not found

I have had to change the initial line from sh to bash because if not source and [[ comparisons fails.

Accept config file path

Give a way to users pass a configuration file path. It's useful when users have only one installation and multiple projects, specially for sysadmins.

Installation script

Needs an installation script to make things easier. Like npm shell script that dowloads the compressed archive, uncompress and put the executable in the user path.

Move current logic to a mongo collection

The current file is not the ideal solution to manage the current state because when you run local it doesn't lock the current state for other environments and when you want to run it in other server you'll have problems.

Implement logging

Implement logging. Needs an option to only show what will run and another option to run and save log.

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.