Skip to content

Migrations system to keep database up-to-date with source code

License

Notifications You must be signed in to change notification settings

bixev/migrations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

Migrations system to keep database up-to-date with source code

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages