1. Go to this page and download the library: Download izniburak/nur-migration 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/ */
izniburak / nur-migration example snippets
# phpmig.php
use Phpmig\Adapter;
use Pimple\Container;
$container = new Container();
$container['db'] = function () {
$dbh = new PDO('mysql:dbname=testdb;host=127.0.0.1','username','passwd');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
};
$container['phpmig.adapter'] = function ($c) {
return new Adapter\PDO\Sql($c['db'], 'migrations');
};
$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';
return $container;
# phpmig
use Phpmig\Adapter;
use Pimple\Container;
$container = new Container();
$container['db'] = function () {
$dbh = new PDO(sprintf('pgsql:dbname=%s;host=%s;password=%s', 'dbname', 'localhost', 'password'), 'dbuser', '');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
};
$container['phpmig.adapter'] = function ($c) {
return new Adapter\PDO\SqlPgsql($c['db'], 'migrations', 'migrationschema');
};
return $container;
# phpmig.php
// do some autoloading of Doctrine here
use Phpmig\Adapter;
use Pimple\Container;
use Doctrine\DBAL\DriverManager;
$container = new Container();
$container['db'] = function () {
return DriverManager::getConnection(array(
'driver' => 'pdo_sqlite',
'path' => __DIR__ . DIRECTORY_SEPARATOR . 'db.sqlite',
));
};
$container['phpmig.adapter'] = function ($c) {
return new Adapter\Doctrine\DBAL($c['db'], 'migrations');
};
$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';
return $container;
use Phpmig\Adapter;
use Pimple\Container;
use Illuminate\Database\Capsule\Manager as Capsule;
$container = new Container();
$container['config'] = [
'driver' => 'xxx',
'host' => 'xxx',
'database' => 'xxx',
'username' => 'xxx',
'password' => 'x',
'charset' => 'xxx',
'collation' => 'xxx',
'prefix' => '',
];
$container['db'] = function ($c) {
$capsule = new Capsule();
$capsule->addConnection($c['config']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
return $capsule;
};
$container['phpmig.adapter'] = function($c) {
return new Adapter\Illuminate\Database($c['db'], 'migrations');
};
$container['phpmig.migrations_path'] = __DIR__ . DIRECTORY_SEPARATOR . 'migrations';
return $container;
use Phpmig\Migration\Migration;
class AddRatingToLolCats extends Migration
{
/**
* Do the migration
*/
public function up()
{
$sql = "ALTER TABLE `lol_cats` ADD COLUMN `rating` INT(10) UNSIGNED NULL";
$container = $this->getContainer();
$container['db']->query($sql);
}
/**
* Undo the migration
*/
public function down()
{
$sql = "ALTER TABLE `lol_cats` DROP COLUMN `rating`";
$container = $this->getContainer();
$container['db']->query($sql);
}
}
<?= " ";
use Phpmig\Migration\Migration;
class %s extends Migration
{
/**
* Do the migration
*/
public function up()
{
$container = $this->getContainer();
}
/**
* Undo the migration
*/
public function down()
{
$container = $this->getContainer();
}
}