|
1 | 1 | PhpDbMigration - full PHP database migration tool |
2 | 2 | ================================================= |
3 | 3 |
|
4 | | -This is a full standalone PHP tool inspired by the rails database migration tool and MyBatis. |
| 4 | +This is a full standalone PHP tool based on symfony console and inspired by the rails database migration tool and MyBatis. |
5 | 5 | It merge the functionnality of the two tools and has been desined to be as flexible as possible. |
6 | 6 |
|
| 7 | +Installing it to your project |
| 8 | +----------------------------- |
| 9 | +Just add it to your composer.json (don't forget to specify your bin directory) |
| 10 | +Warning, all migrate commands must be executed on your root folder like `bin/migrate migrate:command...` |
| 11 | + |
| 12 | + { |
| 13 | + "name": "jdoe/testproject", |
| 14 | + "authors": [ |
| 15 | + { |
| 16 | + "name": "Jhon DOE", |
| 17 | + "email": "jdoe@gmail.com" |
| 18 | + } |
| 19 | + ], |
| 20 | + "require": { |
| 21 | + "php-database-migration/php-database-migration" :"3.4.*" |
| 22 | + }, |
| 23 | + "config": { |
| 24 | + "bin-dir": "bin" |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | +Adding an environment |
| 30 | +--------------------- |
| 31 | +The first thing to do before playing with SQL migrations is to add an environment, let's add the dev one. |
| 32 | + |
| 33 | + |
| 34 | + |
7 | 35 | Initialization |
8 | 36 | -------------- |
| 37 | +Once the environment is added, you have to initialize it (create the changelog table on the good database) |
9 | 38 |
|
10 | | -The first time the tool is run, it needs a first initialization like the following: |
11 | | - |
12 | | - ./migrate --init --driver=<driver> --database=<database> --host=<host> --login=<db_login> --password=<db_password> --changelog=<changelog_table_name> |
| 39 | + |
13 | 40 |
|
14 | | -Example: |
| 41 | +Create a migration |
| 42 | +------------------ |
| 43 | +It is time to create our first migration file. |
15 | 44 |
|
16 | | - ./migrate --init --driver=pgsql --database=php_migration_test --host=localhost --login=my_login --password=my_password --changelog=changelog |
| 45 | + |
17 | 46 |
|
18 | | -wich will create the following directories/files |
| 47 | +Migrations file are like this |
19 | 48 |
|
20 | | - ./environments |
21 | | - |----development.ini |
22 | | - |----preproduction.ini |
23 | | - `----production.ini |
| 49 | + --// add table users |
| 50 | + -- Migration SQL that makes the change goes here. |
| 51 | + create table users (id integer, name text); |
| 52 | + -- @UNDO |
| 53 | + -- SQL to undo the change goes here. |
| 54 | + drop table users; |
24 | 55 |
|
25 | | - ./migrations |
| 56 | +Up and down |
| 57 | +------------------ |
| 58 | +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. |
| 59 | + |
26 | 60 |
|
27 | | -just edit/change the environment ini files in order to match with your database access. |
| 61 | +For developement purpose, it is also possible to up a single migration without taking care of the other ones. |
28 | 62 |
|
29 | | -Usage |
30 | | ------ |
| 63 | + |
31 | 64 |
|
32 | | - Usage: ./migrate command [parameters] [--env=<environment>] |
33 | | - |
34 | | - Commands: |
35 | | - --env=<environment> Environment to configure. Default environment is 'dev'. |
36 | | - --generate <description> Creates a new migration with the provided description. |
37 | | - --up Run unapplied migrations, ALL by default. |
38 | | - --up=<version> Run unapplied migrations up to version (included). |
39 | | - --down Undoes migrations applied to the database. ONE by default. |
40 | | - --down=<version> Undoes migrations applied to the database. Down to version (included). |
41 | | - --force Run or undoes only specified migration (not recommended). |
42 | | - --transactional Rollback all applied migration up or down on error. |
43 | | - --status Show migrations status (applied, unapplied ect...). |
| 65 | +Same thing for down |
44 | 66 |
|
45 | | - Examples: |
46 | | - ./migrate [--generate <migration_name>] |
47 | | - ./migrate [--up | --up=<version> | --down | --down=<version>] [--transactional] [--force] [--env=<environment>] |
48 | | - ./migrate [--status] [--env=<environment>] |
| 67 | + |
0 commit comments