PHP code example of genkgo / migrations

1. Go to this page and download the library: Download genkgo/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/ */

    

genkgo / migrations example snippets



use Genkgo\Migrations\AbstractMigration;

class migration_2014_11_13_11_55 extends AbstractMigration
{

    public function up()
    {
        // your changes here
    }

    public function down()
    {
        // undo changes here
    }
}


use PDO;
use Genkgo\Migrations\Factory;
use Genkgo\Migrations\Adapters\PdoSqliteAdapter;

$adapter = new PdoSqliteAdapter(new PDO('sqlite::memory:'));
$factory = new Factory($adapter);
$directory = __DIR__.'/migrations';
$list = $this->factory->newListFromDirectory($directory);
$result = $list->migrate();


use PDO;
use Genkgo\Migrations\Factory;
use Genkgo\Migrations\Adapters\PdoSqliteAdapter;
use Vendor\DatabaseAbstractLayer\SchemaGenerator;

$adapter = new PdoSqliteAdapter(new PDO('sqlite::memory:'));
$factory = new Factory($adapter, function ($classname) {
    return new $classname(new SchemaGenerator());
});


use Genkgo\Migrations\AbstractMigration;
use Vendor\DatabaseAbstractLayer\SchemaGenerator;

class migration_2014_11_13_11_55 extends AbstractMigration
{
    private $schema;

    public function __construct(SchemaGenerator $schema) {
        $this->schema = $schema;
    }

    public function up()
    {
        // your changes here
    }

    public function down()
    {
        // undo changes here
    }
}


use PDO;
use Genkgo\Migrations\Factory;
use Genkgo\Migrations\Adapters\PdoSqliteAdapter;

$adapter = new PdoSqliteAdapter(new PDO('sqlite::memory:'));
$factory = new Factory($adapter, function ($classname) use ($di) {
    return $di->newInstance($classname);
});


namespace Vendor\MyPlugin;

use Genkgo\Migrations\AbstractMigration;

class migration_2014_11_13_11_55 extends AbstractMigration
{

    public function up () { }
    public function down () { }

}

$directory = __DIR__. '/migrations';
$list = $this->factory->newListFromDirectory($directory,'Vendor\\Plugin\\');
$list->migrate();