-
Notifications
You must be signed in to change notification settings - Fork 23
Description
MMP is a tool to enable automatic creation of MySQL migration scripts and to handle their loading/removal to a given database schema.
It can:
- create initial schema from an existing database
- load the schema into a database (for example on new test or production servers)
- create migration scripts (as PHP classes)
- Load migrations into a database
- Update to a specified revision (time)
The configuration is done by creating a config.ini file in MMP's main folder. A sample config file called config.ini.sample is provided to help a little bit with that.
The location of config file can be overridden via command line option --config="<path_to_file></path_to_file>"
Available configuration options:
Option | Description |
---|---|
host | Hostname of the database server |
user | User on the database server |
password | Password for the database user |
db | Database to track for any schema changes |
exclude_tables | Tables matching this regex pattern will not be tracked for changes. Value should be quoted (ex.) |
savedir | Folder where migration files shall be stored |
verbose | Outputs additional info when executing commands (a bunch of queries at the moment) |
versiontable | Database table where revision numbers of the applied migrations will be stored |
All MMP commands are supplied in the form like this: ./migration.php [configuration] command [command]
!Command | ! Description |
help | List available commands. Use help command for a more detailed description of each. |
schema | Take initial snapshot of the database schema. |
init | Load initial database schema (of what's been created with schema command above). No migrations are loaded after this. |
create | Generate a new migration. |
list | List available and applied migrations. |
migrate | Load or remove migrations. Target migration point is provided as an absolute or relative date from the current moment, in the format supported by strtotime() php function, such as "-2 hours", "2011.03.01 16:00", etc. If nothing is provided, all migrations up to current time will be loaded. |
To start using this tool you must first create the initial schema
./migration.php schema
Then add db/ dir to version control (or whatever else savedir was set to).
Now you can change database structure and then call:
./migration.php create
Add the newly-created migration file to version control, go to the another working copy, update filesystem from VC, and load initial schema
./migration.php init
Now your initial database created and you can migrate to any time
./migration.php migrate -2 hour
Or migrate database to latest version
./migration.php migrate
./migration.php help
MySQL Migration with PHP --------------------------------------------------------------------- help: display this help and exit schema: create schema for initial migration/installation init: load initial schema (install) create: create new migration migrate: migrate to specified time In migrate comand you can use strtotime format Examples: ********************************************************************* ./migrate.php migrate yestarday ./migrate.php migrate -2 hour ./migrate.php migrate +2 month ./migrate.php migrate 20 September 2001 ./migrate.php migrate ******************************************************************** Last example will update your database to last version --------------------------------------------------------------------- Licenced under: GPL v3 Author: Maxim Antonov <max.antonoff@gmail.com></max.antonoff@gmail.com>