|
| 1 | +PhpMySQLMigration - PHP-MySQL database migration tool |
| 2 | +================================================= |
| 3 | +Project created to run migrations on multiple environments |
| 4 | + |
| 5 | +This is a full standalone PHP tool based on [Symfony Console](http://symfony.com/doc/current/components/console). |
| 6 | +It's a fork from https://github.com/alwex/php-database-migration |
| 7 | + |
| 8 | +Usage |
| 9 | +----- |
| 10 | +``` |
| 11 | +$ ./bin/migrate |
| 12 | +Console Tool |
| 13 | +
|
| 14 | +Usage: |
| 15 | + command [options] [arguments] |
| 16 | +
|
| 17 | +Options: |
| 18 | + -h, --help Display this help message |
| 19 | + -q, --quiet Do not output any message |
| 20 | + -V, --version Display this application version |
| 21 | + --ansi Force ANSI output |
| 22 | + --no-ansi Disable ANSI output |
| 23 | + -n, --no-interaction Do not ask any interactive question |
| 24 | + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug |
| 25 | +
|
| 26 | +Available commands: |
| 27 | + help Displays help for a command |
| 28 | + list Lists commands |
| 29 | + migrate |
| 30 | + migrate:init Create the changelog file and file directories |
| 31 | + migrate:addenv Add an environment to work with php db migrate |
| 32 | + migrate:reset Reset database given a clean file |
| 33 | + migrate:create Create a SQL migration |
| 34 | + migrate:up Execute all waiting migration up to [to] option if precised |
| 35 | + migrate:down Rollback all waiting migration down to [to] option if precised |
| 36 | + migrate:status Display the current status of the specified environment |
| 37 | + migrate:seed Seed database with given file. |
| 38 | +``` |
| 39 | + |
| 40 | +Installing it in your project |
| 41 | +----------------------------- |
| 42 | +Just run composer command (don't forget to specify your bin directory) |
| 43 | + |
| 44 | +``` |
| 45 | +composer require filipe07/php-database-migration |
| 46 | +``` |
| 47 | + |
| 48 | + |
| 49 | +Initialization |
| 50 | +-------------- |
| 51 | +Choose folder for migrations and configurations and creates a new database table for tracking the current database changes. |
| 52 | +Warning, all migrate commands must be executed on your root folder like `bin/migrate migrate:command...` |
| 53 | + |
| 54 | +``` |
| 55 | +$ ./bin/migrate migrate:init |
| 56 | +``` |
| 57 | + |
| 58 | + |
| 59 | +Adding an environment |
| 60 | +--------------------- |
| 61 | +The first thing to do before playing with MySQL migrations is to add an environment, let's add the dev one. |
| 62 | + |
| 63 | +``` |
| 64 | +$ ./bin/migrate migrate:addenv |
| 65 | +``` |
| 66 | + |
| 67 | +You will be prompted to answer a series of questions about your environment, and then a config file will be saved |
| 68 | +in `.[environments]/[env].yml`. |
| 69 | + |
| 70 | + |
| 71 | +Create a migration |
| 72 | +------------------ |
| 73 | +It is time to create our first migration file. |
| 74 | + |
| 75 | +``` |
| 76 | +$ ./bin/migrate migrate:create |
| 77 | +``` |
| 78 | + |
| 79 | +Migrations file are like this: |
| 80 | + -- // add table users |
| 81 | + -- Migration SQL that makes the change goes here. |
| 82 | + create table users (id integer, name text); |
| 83 | + -- @UNDO |
| 84 | + -- SQL to undo the change goes here. |
| 85 | + drop table users; |
| 86 | + |
| 87 | + |
| 88 | +List status of migrations |
| 89 | +------------------ |
| 90 | +View all available migrations and their status. |
| 91 | + |
| 92 | +``` |
| 93 | +$ ./bin/migrate migrate:status [env] |
| 94 | ++----------------+---------+------------------+--------------------+ |
| 95 | +| id | version | applied at | description | |
| 96 | ++----------------+---------+------------------+--------------------+ |
| 97 | +| 14679010838251 | | | create table users | |
| 98 | ++----------------+---------+------------------+--------------------+ |
| 99 | +``` |
| 100 | + |
| 101 | + |
| 102 | +Up and down |
| 103 | +----------- |
| 104 | +You can now up all the pending migrations. If you decide to down a migration, the last one will be downed alone to |
| 105 | +prevent mistakes. You will be asked to confirm the downgrade of your database before running the real SQL script. |
| 106 | + |
| 107 | +``` |
| 108 | +$ ./bin/migrate migrate:up [env] |
| 109 | +``` |
| 110 | + |
| 111 | +For development purposes, it is also possible to up a single migration without taking care of the other ones: |
| 112 | + |
| 113 | +``` |
| 114 | +$ ./bin/migrate migrate:up [env] --only=[migrationid] |
| 115 | +``` |
| 116 | + |
| 117 | +or migrate to specific migration (it will run all migrations, including the specified migration) |
| 118 | + |
| 119 | +``` |
| 120 | +$ ./bin/migrate migrate:up [env] --to=[migrationid] |
| 121 | +``` |
| 122 | + |
| 123 | +Same thing for down: |
| 124 | + |
| 125 | +``` |
| 126 | +$ ./bin/migrate migrate:down [env] --only=[migrationid] |
| 127 | +``` |
| 128 | +or |
| 129 | + |
| 130 | +``` |
| 131 | +$ ./bin/migrate migrate:down [env] --to=[migrationid] |
| 132 | +``` |
| 133 | + |
| 134 | + |
| 135 | +Seed file to database |
| 136 | +------------------ |
| 137 | +If you need to seed database with given file |
| 138 | + |
| 139 | +``` |
| 140 | +$ ./bin/migrate migrate:seed [env] {file_location} |
| 141 | +``` |
0 commit comments