1. Go to this page and download the library: Download rkr/php-db-migrations library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rkr / php-db-migrations example snippets
use Kir\DB\Migrations\DBAdapter;
use Kir\DB\Migrations\DBAdapters\PdoDBAdapter;
return [
'statements' => [[
'up' => static fn (DBAdapter $db) =>
$db->exec("ALTER TABLE `my_table` ADD COLUMN `id` INT NOT NULL"),
'down' => static fn (DBAdapter $db) =>
$db->exec("ALTER TABLE `my_table` DROP COLUMN `id`")
]],
];
use Kir\DB\Migrations\DBAdapters\PdoDBAdapter;
use Kir\DB\Migrations\MigrationManager;
use PDO;
use Psr\Log\NullLogger;
$pdoInstance = new PDO('mysql:host=localhost;dbname=app', 'user', 'pass');
$dbAdapter = new PdoDBAdapter($pdoInstance, 'migrations', new NullLogger());
$manager = new MigrationManager($dbAdapter, __DIR__ . '/migrations', new NullLogger());
$manager->migrate();
use Doctrine\DBAL\DriverManager;
use Kir\DB\Migrations\DBAdapters\DoctrineDbalAdapter;
use Kir\DB\Migrations\MigrationManager;
use Psr\Log\NullLogger;
$connection = DriverManager::getConnection([
'url' => 'pgsql://user:pass@localhost:5432/dbname',
]);
$adapter = new DoctrineDbalAdapter($connection);
$manager = new MigrationManager($adapter, __DIR__ . '/migrations', new NullLogger());
$manager->migrate();