A crude version control system for mysql written in php
Effective mysql database version control in one library. Quick and simple to use, but with a rich and flexible API for those who want to customise the set up., (*1)
Install with composer:, (*2)
$ composer require smrtr/mysql-version-control:~1.0
Your database versions will be stored in
<project_root>/db/versions by default.
The sql for each version is stored in a directory directly under this directory.
So the directories are named
db/versions/2 and so on.
Each version must contain at least one of the following files:, (*3)
schema.sql- always runs first, contains
CREATE TABLE IF NOT EXISTSand
ALTERstatements and the like.
DELETEstatements and the like.
testing.sql- same as
data.sqlbut with test data which doesn't need to exist outside of testing environments.
runme.php- a custom php hook for running php code with your version.
The files for each version are run in the order specified above., (*4)
The quickest way to get started is to set up your database configuration in a file at
See examples/db.ini for an example of this file., (*6)
Define a list of environments and testing environments under the tag
List out all of the available environments with entries like so:
environments = "local-dev"., (*8)
List the testing environments like so:
testing_environments = "local-dev".
This list is a subset of the environments list and comprises those environments which should receive test data., (*9)
You must define two database connection configurations for each environment.
The two configurations are called
runtime and they are used for processing schema changes and data
changes respectively., (*10)
Each connection requires a
database. You can optionally add a
The command line tool is located at
Remember it! It stands for Smrtr MYsql VERsion control., (*13)
vendor/bin/smyver.php status <environment> to get the current status of the database for that environment., (*14)
vendor/bin/smyver.php up <environment> to install or update the database on the given environment.
This command looks at the available versions in the
db/versions directory and applies new versions sequentially
from the current version., (*15)
If this is the first run on the given environment, then a table called
db_config is created and used to store the
current database version., (*16)
You may optionally provide a second argument specifying the mysql client binary to use. This argument is required if mysql is not on your $PATH., (*17)
Use this flag to skip the schema files. This can be useful if you use an ORM to build the database schema., (*18)
Use this flag to install a provisional version. This allows you to test out your database version, which may currently
be in development, before you commit to it by giving it a version number. This command looks for your provisional
<project_root>/db/versions/new by default., (*19)
vendor/bin/smyver.php teardown <environment> to tear down the tables on the given environment., (*20)
This command is useful for development & testing environments., (*21)
confirm option to bypass the confirmation prompt, e.g., (*22)
vendor/bin/smyver.php <environment> --confirm
These options can be used with all console commands., (*23)
Specify a configuration adapter to use instead of the Ini adapter which is used by default., (*24)
If you are using one of the standard adapters shipped with this package you only need to enter the class name, e.g. PhpFile., (*25)
If you are using your own custom adapter class then you must provide a fully qualified class name and your class
You can specify one or more constructor parameters for the configuration adapter class with this option., (*27)
To specify multiple parameters simply use the option more than once, e.g.
would result in the configuration adapter being instantiated like so:
new $adapter("One", "Two")., (*28)
Use this option to provide a custom path to your provisional version. Your custom path is relative to the versions path., (*29)
Use this option, or
-p for short, to provide a custom path to your versions.
This allows you to override the default versions path which is
If the path provided is not an absolute path then it is assumed to be relative to the project root., (*30)