Skip to content

Commit f6cb703

Browse files
author
Alexandre GUIDET
committed
Merge branch 'master' of github.com:alwex/php-database-migration into release-3.4.0
2 parents b87af3a + cfe34f6 commit f6cb703

1 file changed

Lines changed: 50 additions & 31 deletions

File tree

README.md

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,67 @@
11
PhpDbMigration - full PHP database migration tool
22
=================================================
33

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.
55
It merge the functionnality of the two tools and has been desined to be as flexible as possible.
66

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.3.*"
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+
![alt tag](http://tikotepadventure.com/files/php-database-migration/addenv.gif)
34+
735
Initialization
836
--------------
37+
Once the environment is added, you have to initialize it (create the changelog table on the good database)
938

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+
![alt tag](http://tikotepadventure.com/files/php-database-migration/init.gif)
1340

14-
Example:
41+
Create a migration
42+
------------------
43+
It is time to create our first migration file.
1544

16-
./migrate --init --driver=pgsql --database=php_migration_test --host=localhost --login=my_login --password=my_password --changelog=changelog
45+
![alt tag](http://tikotepadventure.com/files/php-database-migration/create.gif)
1746

18-
wich will create the following directories/files
47+
Migrations file are like this
1948

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;
2455

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+
![alt tag](http://tikotepadventure.com/files/php-database-migration/status.gif)
2660

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.
2862

29-
Usage
30-
-----
63+
![alt tag](http://tikotepadventure.com/files/php-database-migration/uponly.gif)
3164

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
4466

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+
![alt tag](http://tikotepadventure.com/files/php-database-migration/downonly.gif)

0 commit comments

Comments
 (0)