zoltanlaca/dibi-migrations

Dibi Database Migrations Library

v1.0.3 2024-07-08 21:03 UTC

This package is auto-updated.

Last update: 2024-10-08 21:39:57 UTC


README

Dibi Database Migrations Library

Installation

composer require zoltanlaca/dibi-migrations

Basic configuration

<?php
declare(strict_types=1);

use Dibi\Connection;
use Zoltanlaca\DibiMigrations\Configuration;
use Zoltanlaca\DibiMigrations\Exceptions\ConnectionException;
use Zoltanlaca\DibiMigrations\Migrations;

include_once dirname(__DIR__) . '/vendor/autoload.php';

try {
    $connection = new Connection([
        'driver' => 'mysqli',
        'host' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'dibi_migrations',
    ]);
} catch (\Dibi\Exception $exception) {
    echo $exception->getMessage(). PHP_EOL;
    exit;
}

$config = New Configuration(
    $connection,
   __DIR__ . '/Migrations',
   'Zoltanlaca\DibiMigrations\Examples\Migrations',
   'migrations'
);

try {
    $migrations = new Migrations($config);
    $migrations->migrateUp();
} catch (ConnectionException $exception) {
    echo $exception->getMessage(). PHP_EOL;
    exit;
}

Migrate to newest version

$migrations->migrateUp();

Migrate to defined version only

$migrations->migrateUp(20230518085154);

Revert migration to first version

$migrations->migrateDown();

Revert migration to defined version

$migrations->migrateUp(20230518085154);