1. Jiri Knesl
  2. Miggy


Miggy howto



	- collection of authors (asdf asdf asdf)
	- Jiri Knesl (http://www.knesl.com) <jiri.knesl@gmail.com>
dibi - David Grudl (http://www.grudl.cz) <david@grudl.cz>


How to install:

1) Move folders Miggy and dibi in libs to your library. Classes use namespace.
If you're not using autoloader, ply try autoloader in Nette framework (http://www.nette.org).

2) Put runner.php to your application scripts folder, migration-config.php to your configs folder.

3) Create migrations folder.

4) Edit runner.php and fix paths to config folder.

5) Setup your application in config.

6) Try "php runner.php" - usage should be visible.


How to use:


What is env and project?

The project is application you develop can depend on another submodules (using svn externals, git or mercurial subrepos and so on). Miggy allows you to run migrations on multiple projects. Note that preferred way is to have each project in own database.

Env is your environment. In most cases your environments will be 'development', 'test', 'staging', 'production'.


Hot to setup?

Put to your migration-config.php:

$setup = new \Miggy\Setup;
		'env'=>'development', 			# your ENVironment
		'project'=>'default', 			# your PROJECT
		'adapter'=>'MySQL', 			# can be any adapter supported by dibi
		'host'=>'localhost', 			# database host
		'user'=>'root',					# database user
		'password'=>'password', 		# database password
		'database'=>'proj_dev', 		# database name
		'charset'=>'utf-8', 			# connection charset
		'migrations_path'=>__DIR__ . '/migrations', 
										# folder where yours
										# migrations will be stored
		'migrations_log_path'=>__DIR__ . '/migration-logs/log.txt'
										# path to logs

// ... other combinations of env and projects


Hot to test my connections are ok?

php runner.php setup ENV=development PROJECT=default 	# if you'd like to test
														# specific setup
php runner.php setup-all ENV=development				# if you would like to
														# test all projects in ENV

Note: setup / setup-all will creat table schema_info in your database with one
column and one field type INT with number 0.

Each time migration is processed, system update schema_info for given database.


How to create migration?

php runner.php generate MigrationName ENV=development PROJECT=default

Miggy will create in your migrations folder new file in format:

{migraion number}_{migration name}.php

Migration number is greater than highest number in given folder.

If you have migrations:

php runner.php generate CreateCommentsTable

it will create file 005_CreateCommentsTable.php


How to run migrations?

php runner.php migrate ENV=development PROJECT=default
php runner.php migrate # in case you have default values
php runner.php migrate-all ENV=development # migrate all projects in given environment


Hot to run down?

php runner.php migrate VERSION=23 ENV=development PROJECT=default # in case your version is greater than 23
php runner.php migrate VERSION=23 # in case you have default values
php runner.php migrate-all ENV=development VERSION=23 # in case you'd like to migrate down everything in default project



Miggy - Modified BSD licence
Dibi - Dibi licence (http://www.dibi.org)


Theory of operation:

Each time you run runner.php
1) Setup is found and runned in runner.php (not Runner class);
2) Options are parsed in OptsParser.
3) Dispatcher from Opts and Setup will tell, what is going to happen (migrating up or down).
4) MigrationsSearch finds migrations between actual and given number.
5) Migration classes are instantiated. Depending on migrating up or down - methods up and down are called.
6) Each time migration method passes, MigrationNumberNotifier changes actual migration number in database.
7) Each time SQL query fails, it is sent to Logger and shown to the user