amyboyd/mongrate

A command-line tool for applying migrations to a MongoDB database

Installs: 1 108

Dependents: 1

Stars: 3

Watchers: 3

Forks: 3

Open Issues: 1

Language: PHP

1.3.10 2015-08-21 10:03 UTC

README

Build Status Code Coverage

A command-line tool for applying migrations to a MongoDB database. Migrations are non-linear, and can be tested by writing simple YML files.

Doctrine's Mongo abstraction layer is used to provide a clean database API. Mongrate does not use Doctrine's Mongo ODM - this is to avoid having to write mapping classes and to make it very quick to write migrations.

At the moment, Mongrate does not support applying migrations to multiple databases.

Example migrations can be found in resources/examples/.

Symfony 2 users can use MongrateBundle to integrate easily with a Symfony 2 project.

Table of content:

Installation

Mongrate is available via Composer.

Once you have downloaded Mongrate, run these commands:

php composer.phar install
chmod a+x mongrate
cp config/parameters.yml.dist config/parameters.yml

Edit config/parameters.yml and enter your MongoDB connection information.

Configuration

Your parameters.yml you should have something similar to this.

parameters:
    mongodb_server: 'mongodb://localhost:27017'
    mongodb_db: my_db
    migrations_directory: migrations
Parameter Required Description mongodb_server required URI for your mongodb server. mongodb_db required Database name. migrations_directory required The directory where your migration files are to be kept.

Note: Don't add a trailing slash in migrations_directory parameter value.

Usage

Generate Migration

To generate a migration file, with the name "UpdateAddressStructure":

./mongrate generate-migration UpdateAddressStructure

List Migrations

To list available migrations:

./mongrate list-migrations

Toggle Migration

To toggle a migration (useful while writing your migration):

./mongrate toggle 20140523_UpdateAddressStructure

Migrate up

To migrate up:

./mongrate up 20140523_UpdateAddressStructure [--force]

Migrate down

To migrate down:

./mongrate down 20140523_UpdateAddressStructure [--force]

Test Migration

To verify a migration with it's YML test files:

./mongrate test 20140523_UpdateAddressStructure (up|down|empty) [--pretty]

NOTE: If you leave migration type empty after the migration name it will test both migrations up and down.

Contributing

See the file CONTRIBUTING.md