|
1 | 1 | mysql-version-control |
2 | 2 | ===================== |
3 | 3 |
|
4 | | -A crude version control system for a mysql database. |
| 4 | +Effective mysql database version control in one library. Quick and simple to use, but with a rich and flexible |
| 5 | +API for those who want to customise the set up. |
5 | 6 |
|
6 | | -## Installation |
7 | | -Use composer. |
8 | | -Add `"smrtr/mysql-version-control": "~1.0"` to the `requires` section of your project's composer.json then run |
9 | | -`composer update`. |
| 7 | +## Requirements |
| 8 | + - PHP >= 5.4 |
| 9 | + - Composer |
| 10 | + - MySQL client |
10 | 11 |
|
11 | | -## Configuration |
12 | | -Your database configuration will be stored at `<project_root>/db/db.ini`. In this file you will define a list of |
13 | | -environments and then define database configurations for each environment. |
| 12 | +Install with composer: |
14 | 13 |
|
15 | | -### environments |
16 | | -Define a list of environments under the `[environments]` tag using the format `environments[] = "development"`. The |
17 | | -CLI tool will add commands for each environment listed here. |
| 14 | + $ composer require smrtr/mysql-version-control:~1.0 |
18 | 15 |
|
19 | | -You may also define a list of testing environments using the format `testing_environments[] = "testing"`. The CLI tool |
20 | | -will only apply test data on the environments listed here. |
| 16 | +# Versioning |
| 17 | +Your database versions will be stored in `<project_root>/db/versions` by default. |
| 18 | +The sql for each version is stored in a directory directly under this directory. |
| 19 | +So the directories are named `db/versions/1`, `db/versions/2` and so on. |
| 20 | +Each version must contain at least one of the following files: |
21 | 21 |
|
22 | | -### databases |
23 | | -You must define two database configurations for each environment using the name of the environment as a tag. |
24 | | -The two configurations are called `buildtime` and `runtime` and they are used for processing schemas and data |
25 | | -respectively. Each configuration requires a `host`, `user`, `password` and `database` entry. |
| 22 | + - `schema.sql` - always runs first, contains `CREATE TABLE IF NOT EXISTS` and `ALTER` statements and the like. |
| 23 | + - `data.sql` - contains `REPLACE INTO`, `INSERT`, `UPDATE` and `DELETE` statements and the like. |
| 24 | + - `testing.sql` - same as `data.sql` but with test data which doesn't need to exist outside of testing environments. |
| 25 | + - `runme.php` - a custom php hook for running php code with your version. |
26 | 26 |
|
27 | | -### Example db.ini |
| 27 | +The files for each version are run in the order specified above. |
28 | 28 |
|
29 | | - [environments] |
30 | | - environments[] = "development" |
31 | | - environments[] = "production" |
| 29 | +# Configuration |
| 30 | +The quickest way to get started is to set up your database configuration in a file at `<project_root>/db/db.ini`. |
32 | 31 |
|
33 | | - testing_environments[] = "development" |
| 32 | +See *examples/db.ini* for an example of this file. |
34 | 33 |
|
35 | | - [development] |
36 | | - runtime.host = "localhost" |
37 | | - runtime.user = "buzz" |
38 | | - runtime.password = "lightyear" |
39 | | - runtime.database = "buzz" |
| 34 | +### Environments |
| 35 | +Define a list of environments and testing environments under the tag `[environments]`. |
40 | 36 |
|
41 | | - buildtime.host = "localhost" |
42 | | - buildtime.user = "buzz" |
43 | | - buildtime.password = "lightyear" |
44 | | - buildtime.database = "buzz" |
| 37 | +List out all of the available environments with entries like so: `environments[] = "local-dev"`. |
45 | 38 |
|
46 | | - [production] |
47 | | - runtime.host = "localhost" |
48 | | - runtime.user = "root" |
49 | | - runtime.password = "root" |
50 | | - runtime.database = "buzz" |
| 39 | +List the testing environments like so: `testing_environments[] = "local-dev"`. |
| 40 | +This list is a subset of the environments list and comprises those environments which should receive test data. |
51 | 41 |
|
52 | | - buildtime.host = "localhost" |
53 | | - buildtime.user = "buzz" |
54 | | - buildtime.password = "lightyear" |
55 | | - buildtime.database = "buzz" |
| 42 | +### Connections |
| 43 | +You must define two database connection configurations for each environment. |
| 44 | +The two configurations are called `buildtime` and `runtime` and they are used for processing schema changes and data |
| 45 | +changes respectively. |
56 | 46 |
|
57 | | -## Versioning |
58 | | -Your database versions will be stored in `<project_root>/db/versions` by default. |
59 | | -The sql for each version is stored in a directory directly under this directory. |
60 | | -So the directories are named `db/versions/1`, `db/versions/2` and so on. |
61 | | -Each version must contain at least one of the following files: |
| 47 | +Each connection requires a `host`, `user`, `password` and `database`. You can optionally add a `port`. |
62 | 48 |
|
63 | | - - `schema.sql` - always runs first, contains `CREATE TABLE IF NOT EXISTS` and `ALTER` statements. |
64 | | - - `data.sql` - contains `REPLACE INTO`, `INSERT`, `UPDATE` and `DELETE` statements and the like. |
65 | | - - `testing.sql` - same as `data.sql` but with test data which doesn't need to exist outside of testing environments. |
66 | | - - `runme.php` - a custom php hook for running, for example, import tasks. |
| 49 | +# Command Line Interface |
| 50 | +The command line tool is located at `vendor/bin/smyver.php`. |
67 | 51 |
|
68 | | -The files are run in the order specified above. |
| 52 | +*Remember it!* It stands for **S**mrtr **MY**sql **VER**sion control. |
69 | 53 |
|
70 | | -## Usage |
71 | | -This package will put two CLI scripts into your project's `vendor/bin` directory. |
| 54 | +## status |
| 55 | +Run `vendor/bin/smyver.php status <environment>` to get the current status of the database for that environment. |
72 | 56 |
|
73 | | -### up |
74 | | -Run `vendor/bin/up <environment>` to install or update the database on the given environment. |
| 57 | +## up |
| 58 | +Run `vendor/bin/smyver.php up <environment>` to install or update the database on the given environment. |
75 | 59 | This command looks at the available versions in the `db/versions` directory and applies new versions sequentially |
76 | 60 | from the current version. |
77 | 61 |
|
78 | 62 | If this is the first run on the given environment, then a table called `db_config` is created and used to store the |
79 | 63 | current database version. |
80 | 64 |
|
| 65 | +You may optionally provide a second argument specifying the mysql client binary to use. |
| 66 | +This argument is required if mysql is not on your $PATH. |
| 67 | + |
81 | 68 | #### `--no-schema` |
82 | 69 | Use this flag to skip the schema files. This can be useful if you use an ORM to build the database schema. |
83 | 70 |
|
84 | | -#### `--versions-path` |
85 | | -Use this option, or `-p` for short, to provide a custom path to your versions. |
86 | | -This allows you to override the default versions path which is `<project_root>/db/versions`. |
87 | | - |
88 | 71 | #### `--install-provisional-version` |
89 | 72 | Use this flag to install a provisional version. This allows you to test out your database version, which may currently |
90 | 73 | be in development, before you commit to it by giving it a version number. This command looks for your provisional |
91 | 74 | version in `<project_root>/db/versions/new` by default. |
92 | 75 |
|
93 | | -#### `--provisional-version` |
94 | | -Use this option to provide a custom path to your provisional version. Your custom path is relative to the versions path. |
| 76 | +## teardown |
| 77 | +Run `vendor/bin/smyver.php teardown <environment>` to tear down the tables on the given environment. |
95 | 78 |
|
96 | | -### teardown |
97 | | -Run `vendor/bin/teardown <environment>` to tear down the tables on the given environment. |
98 | | - |
99 | | -This command is useful for development & testing developments where you may wish to, for example, tear down your |
100 | | -database between test runs. |
| 79 | +This command is useful for development & testing environments. |
101 | 80 |
|
102 | 81 | Use the `confirm` option to bypass the confirmation prompt, e.g. |
103 | 82 |
|
104 | | - vendor/bin/teardown <environment> --confirm |
| 83 | + vendor/bin/smyver.php <environment> --confirm |
| 84 | + |
| 85 | +## Global CLI options |
| 86 | +These options can be used with all console commands. |
| 87 | + |
| 88 | +#### `--config-adapter` |
| 89 | +Specify a configuration adapter to use instead of the Ini adapter which is used by default. |
| 90 | + |
| 91 | +If you are using one of the standard adapters shipped with this package you only need to enter the class name, |
| 92 | +e.g. PhpFile. |
| 93 | + |
| 94 | +If you are using your own custom adapter class then you must provide a fully qualified class name and your class |
| 95 | +must implement `Smrtr\MysqlVersionControl\DbConfigAdapter\ConfigAdapterInterface`. |
| 96 | + |
| 97 | +#### `--config-adapter-param` |
| 98 | +You can specify one or more constructor parameters for the configuration adapter class with this option. |
| 99 | + |
| 100 | +To specify multiple parameters simply use the option more than once, e.g. |
| 101 | +`--config-adapter-param="One" --config-adapter-param="Two"` |
| 102 | +would result in the configuration adapter being instantiated like so: `new $adapter("One", "Two")`. |
| 103 | + |
| 104 | +#### `--provisional-version` |
| 105 | +Use this option to provide a custom path to your provisional version. Your custom path is relative to the versions path. |
| 106 | + |
| 107 | +#### `--versions-path` |
| 108 | +Use this option, or `-p` for short, to provide a custom path to your versions. |
| 109 | +This allows you to override the default versions path which is `<project_root>/db/versions`. |
| 110 | +If the path provided is not an absolute path then it is assumed to be relative to the project root. |
0 commit comments