Skip to content

Commit 99cee05

Browse files
committed
Updated readme
1 parent 8ba4331 commit 99cee05

1 file changed

Lines changed: 81 additions & 1 deletion

File tree

README.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,84 @@
11
mysql-version-control
22
=====================
33

4-
A crude version control system for mysql
4+
A crude version control system for a mysql database.
5+
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`.
10+
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.
14+
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.
18+
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.
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.
26+
27+
### Example db.ini
28+
29+
[environments]
30+
environments[] = "development"
31+
environments[] = "production"
32+
33+
testing_environments[] = "development"
34+
35+
[development]
36+
runtime.host = "localhost"
37+
runtime.user = "buzz"
38+
runtime.password = "lightyear"
39+
runtime.database = "buzz"
40+
41+
buildtime.host = "localhost"
42+
buildtime.user = "buzz"
43+
buildtime.password = "lightyear"
44+
buildtime.database = "buzz"
45+
46+
[production]
47+
runtime.host = "localhost"
48+
runtime.user = "root"
49+
runtime.password = "root"
50+
runtime.database = "buzz"
51+
52+
buildtime.host = "localhost"
53+
buildtime.user = "buzz"
54+
buildtime.password = "lightyear"
55+
buildtime.database = "buzz"
56+
57+
## Versioning
58+
Your database versions will be stored in `<project_root>/db/versions`. The sql for each version is stored in a directory
59+
directly under this directory. So the directories are named `db/versions/1`, `db/versions/2` and so on.
60+
Each version must contain at least one of the following files:
61+
62+
- `schema.sql` - always runs first, contains `CREATE TABLE IF NOT EXISTS` and `ALTER` statements.
63+
- `data.sql` - contains `REPLACE INTO`, `INSERT`, `UPDATE` and `DELETE` statements and the like.
64+
- `testing.sql` - same as `data.sql` but with test data which doesn't need to exist outside of testing environments.
65+
- `runme.php` - a custom php hook for running, for example, import tasks.
66+
67+
The files are run in the order specified above.
68+
69+
## Usage
70+
This package will put two CLI scripts into your project's `vendor/bin` directory.
71+
72+
### up
73+
Run `vendor/bin/up <environment>` to install or update the database on the given environment.
74+
This command looks at the available versions in the `db/versions` directory and applies new versions sequentially
75+
from the current version.
76+
77+
If this is the first run on the given environment, then a table called `db_config` is created and used to store the
78+
current database version.
79+
80+
### teardown
81+
Run `vendor/bin/teardown <environment>` to tear down the database on the given environment.
82+
83+
This command is useful for development & testing developments where you may wish to, for example, tear down your
84+
database between test runs.

0 commit comments

Comments
 (0)