Beispiel #1
0
// init
$INTEND_VERSION = isset($argv[1]) ? $argv[1] : '99991231235959';
// functions
function print_migration_status($direction, $classname, $version)
{
    echonl('================================================================================');
    echonl($classname . '.' . strtolower($direction) . '() is executed.');
    echonl('Schema version is ' . $version . ' now.');
}
// connect db connection
$db = Context::get('db');
$db->connect();
$schema_version = new SchemaVersion();
if ($schema_version->count() == 0) {
    $schema_version->version = 0;
    $schema_version->save();
}
$schema_version = $schema_version->find();
// read migration files...
$files = get_files(Config::get('migr_dir'));
if ($INTEND_VERSION >= $schema_version->version) {
    sort($files);
    $direction = 'UP';
} else {
    rsort($files);
    $direction = 'DOWN';
}
for ($i = 0; $i < count($files); $i++) {
    $file = $files[$i];
    $matches = Migration::parse_migration_filename($file);
    if (!empty($matches)) {