Skip to content

Commit f66faee

Browse files
authored
Merge pull request #15 from joegreen88/master
For release 1.3
2 parents 816c852 + 297ba93 commit f66faee

50 files changed

Lines changed: 2353 additions & 397 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Changelog
2+
=========
3+
4+
## 1.3.0 (wip)
5+
6+
### General Improvements
7+
8+
- Added a new command: `status`
9+
- Added composer parameter loading to CLI commands
10+
- Bundle all commands into single script smyver.php
11+
- Added port configuration option
12+
- Refactor: implemented the command pattern
13+
- Refactor: implemented the configuration adapter pattern
14+
15+
### Configuration adapters:
16+
17+
- Ini (the default adapter)
18+
- PhpArray
19+
- PhpFile
20+
21+
### Up command:
22+
23+
- Option `--provisional-version` is relative to project root if not an absolute path
24+
25+
## 1.2.0
26+
27+
### Up command:
28+
29+
- Added option `--install-provisional-version`
30+
- Added option `--provisional-version`
31+
32+
## 1.1.0
33+
34+
### Up command:
35+
36+
- Added option `--no-schema`
37+
- Added option `--versions-path`

README.md

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,110 @@
11
mysql-version-control
22
=====================
33

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

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
1011

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:
1413

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
1815

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:
2121

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

27-
### Example db.ini
27+
The files for each version are run in the order specified above.
2828

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`.
3231

33-
testing_environments[] = "development"
32+
See *examples/db.ini* for an example of this file.
3433

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]`.
4036

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"`.
4538

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

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

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`.
6248

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`.
6751

68-
The files are run in the order specified above.
52+
*Remember it!* It stands for **S**mrtr **MY**sql **VER**sion control.
6953

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

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.
7559
This command looks at the available versions in the `db/versions` directory and applies new versions sequentially
7660
from the current version.
7761

7862
If this is the first run on the given environment, then a table called `db_config` is created and used to store the
7963
current database version.
8064

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+
8168
#### `--no-schema`
8269
Use this flag to skip the schema files. This can be useful if you use an ORM to build the database schema.
8370

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-
8871
#### `--install-provisional-version`
8972
Use this flag to install a provisional version. This allows you to test out your database version, which may currently
9073
be in development, before you commit to it by giving it a version number. This command looks for your provisional
9174
version in `<project_root>/db/versions/new` by default.
9275

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

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

10281
Use the `confirm` option to bypass the confirmation prompt, e.g.
10382

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.

bin/smyver.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* @package Smrtr\MysqlVersionControl\Bin
5+
* @author Joe Green <joe.green@smrtr.co.uk>
6+
*/
7+
8+
require_once realpath(dirname(__FILE__).'/../../../autoload.php');
9+
10+
$app = new \Symfony\Component\Console\Application('smyver');
11+
12+
$app->add(new \Smrtr\MysqlVersionControl\Command\Status);
13+
$app->add(new \Smrtr\MysqlVersionControl\Command\Up);
14+
$app->add(new \Smrtr\MysqlVersionControl\Command\Teardown);
15+
16+
$app->run();

bin/teardown

100644100755
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
#!/usr/bin/env php
2-
<?php
3-
include('teardown.php');
1+
#!/usr/bin/env bash
2+
3+
this_dir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
php "$this_dir/smyver.php" teardown "$@"

bin/teardown.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

bin/up

100644100755
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
#!/usr/bin/env php
2-
<?php
3-
include('up.php');
1+
#!/usr/bin/env bash
2+
3+
this_dir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
php "$this_dir/smyver.php" up "$@"

bin/up.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "smrtr/mysql-version-control",
33
"description": "A crude version control system for mysql written in php",
44
"keywords": ["database", "db", "mysql", "version control", "version", "migration", "update", "data", "structure"],
5-
"bin": ["bin/up", "bin/teardown"],
5+
"bin": ["bin/up", "bin/teardown", "bin/smyver.php"],
66
"license": "MIT",
77
"authors": [
88
{
@@ -11,8 +11,8 @@
1111
}
1212
],
1313
"require": {
14-
"symfony/console": "~2.3",
15-
"symfony/process": "~2.5",
14+
"symfony/console": "~2.7",
15+
"symfony/process": "~2.7",
1616
"hearstuk/zf1-component-config": "~1.1"
1717
},
1818
"autoload": {

0 commit comments

Comments
 (0)