This migration will help you with updating database whith new versions of source code, (*1)
Installation
It's recommended that you use Composer to install InterventionSDK., (*2)
composer require bixev/migrations "~1.0"
This will install this library and all required dependencies., (*3)
so each of your php scripts need to require composer autoload file, (*4)
<?php
require 'vendor/autoload.php';
Usage
Basic usage
Use a given or custom migration store. It will store your migrations versions., (*5)
$migrationsStore = new \Bixev\Migrations\VersionStore\MysqlVersionStore();
$migrationsStore->setDb(new PDO(''), 'table_name');
Instanciate migrations API, (*6)
$migrationsApi = new \Bixev\Migrations\API($migrationsStore);
You have to give the api as many updaters as you have migrations file extensions, (*7)
$migrationsApi->setUpdater('php', new \Bixev\Migrations\Updater\PhpUpdater());
$mysqlUpdater = new \Bixev\Migrations\Updater\MysqlUpdater();
$mysqlUpdater->setQueryExecutor(
function ($query) use ($pdoMysql) {
$replacements = ['${DEFAULT_ENGINE}' => 'pouet'];
$query = str_replace(array_keys($replacements), array_values($replacements), $query);
$pdoMysql->query($query);
}
);
$migrationsApi->setUpdater('sql', $mysqlUpdater);
Then, simply update with namespace and updates directory, (*8)
$migrationsApi->update('namespace', 'update/directory');
Log
You can use logger to log update informations., (*9)
$logger = new \Bixev\LightLogger\StdLogger();
$migrationsStore = new \Bixev\Migrations\VersionStore\MysqlVersionStore($logger);
$migrationsApi = new \Bixev\Migrations\API($migrationsStore, $logger);