A command-line tool for applying migrations to a MongoDB database
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
Symfony 2 users can use MongrateBundle to integrate easily with a Symfony 2 project.
Table of content:
- How to run tests
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
config/parameters.yml and enter your MongoDB connection information.
parameters.yml you should have something similar to this.
parameters: mongodb_server: 'mongodb://localhost:27017' mongodb_db: my_db migrations_directory: migrationsParameter 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.
To generate a migration file, with the name "UpdateAddressStructure":
./mongrate generate-migration UpdateAddressStructure
To list available migrations:
To toggle a migration (useful while writing your migration):
./mongrate toggle 20140523_UpdateAddressStructure
To migrate up:
./mongrate up 20140523_UpdateAddressStructure [--force]
To migrate down:
./mongrate down 20140523_UpdateAddressStructure [--force]
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
See the file CONTRIBUTING.md