hipay / php-database-migration
rake and mybatis SQL migration tool
Requires
- php: >=5.4.0
- cocur/slugify: ^2.0
- symfony/config: ^3.0 || ^2.0
- symfony/console: ^3.0 || ^2.0
- symfony/process: ^3.0 || ^2.0
- symfony/yaml: ^3.0
Requires (Dev)
README
This is a full standalone PHP tool based on symfony console and inspired by the rails database migration tool and MyBatis. It merge the functionnality of the two tools and has been desined to be as flexible as possible.
Installing it to your project
Just add it to your composer.json (don't forget to specify your bin directory)
Warning, all migrate commands must be executed on your root folder like bin/migrate migrate:command...
{
"name": "jdoe/testproject",
"authors": [
{
"name": "Jhon DOE",
"email": "jdoe@gmail.com"
}
],
"require": {
"php-database-migration/php-database-migration" :"3.4.*"
},
"config": {
"bin-dir": "bin"
}
}
Adding an environment
The first thing to do before playing with SQL migrations is to add an environment, let's add the dev one.
Initialization
Once the environment is added, you have to initialize it (create the changelog table on the good database)
Create a migration
It is time to create our first migration file.
Migrations file are like this
--// add table users
-- Migration SQL that makes the change goes here.
create table users (id integer, name text);
-- @UNDO
-- SQL to undo the change goes here.
drop table users;
Up and down
You can now up all the pending migrations. If you decided to down a migration, the last one will be downed alone to prevent from mistake. You will be asked to confirm the downgrade of your database before runing the real SQL script.
For developement purpose, it is also possible to up a single migration without taking care of the other ones.
Same thing for down