None of them were perfect for my needs and since the architecture for migrations is pretty simple, I decided to write my own and open-source the results, a php migrations infrastructure called MP.
A few of the features I wanted in MP:
- Easy-to-use
- 100% PHP 5+ implementation
- Command-line utility
- API access for integration into existing apps, frameworks, or ORMs.
- Ability to execute arbitrary code in each migration
- Rollback capabilities
- "Clean" option to rebuild app state from scratch
- Persist current version in a file or in DB
- Prevent collisions of migrations
- Automatically preserve migrations order without manual sorting effort
Getting Started with MP
One you download mp, you can migration-enable your application in moments:
$ cd myproject
# Migration-enable myproject by creating a first migration
$ mp -c create
MP - The PHP Migrator.
Created migration 20090717_014019 at ./migrations/20090717_014019.php.
# migrate to latest migration
$ mp
MP - The PHP Migrator.
Upgrading from version 0 to 20090717_014019.
Running Upgrade: Migration created at 20090717_014019.
Upgrading to 20090717_014019 succeeded.
To implement the specifics of your migration code, just edit the corresponding migration file's up() method.
Integration
MP's API is intended as an integration point for frameworks to be able to directly implement migrations support without having to write a migrations infrastructure from scratch. Your framework's CLI utilities can programmatically configure, execute and create migrations easily. MP can also be configured with a delegate class to which all migrations have access, making it easy to bootstrap your framework before running migrations so that all of your framework's infrastructure is available for use inside the migrations with no additional effort.
Conclusion
I hope that MP can become a widely adoption standard for php migrations. I will continue to work on it and integrate it into the PHOCOA php framework and also add support for SQL migrations with Propel.
4 comments: