bixev / migrations
Bixev database migrations library
1.2.1
2019-02-06 09:01 UTC
Requires
- php: >=7.2
- bixev/light-logger: >=1.0.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This migration will help you with updating database whith new versions of source code
Installation
It's recommended that you use Composer to install InterventionSDK.
composer require bixev/migrations "~1.0"
This will install this library and all required dependencies.
so each of your php scripts need to require composer autoload file
<?php require 'vendor/autoload.php';
Usage
Basic usage
Use a given or custom migration store. It will store your migrations versions.
$migrationsStore = new \Bixev\Migrations\VersionStore\MysqlVersionStore(); $migrationsStore->setDb(new PDO(''), 'table_name');
Instanciate migrations API
$migrationsApi = new \Bixev\Migrations\API($migrationsStore);
You have to give the api as many updaters as you have migrations file extensions
$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
$migrationsApi->update('namespace', 'update/directory');
Log
You can use logger to log update informations.
$logger = new \Bixev\LightLogger\StdLogger(); $migrationsStore = new \Bixev\Migrations\VersionStore\MysqlVersionStore($logger); $migrationsApi = new \Bixev\Migrations\API($migrationsStore, $logger);