Simple migration is a minimalist tool to manage your database versioning.
composer require fabiopaiva/pdo-simple-migration
This library tries to find a file called config.php in working directory with PDO setup, if file doesn't exist, you can send PDO parameters in command line.
<?php
return [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=myDb;port=3306;charset=UTF8',
'username' => 'root',
'password' => 'pass',
],
'table' => 'migrations',
'dir' => 'migrations'
];
table
is the name of database table to control your versioning, migrations is default.
dir
is the path where you want to store you migrations file.
List current status of your migrations
vendor/bin/migration status
Generate a empty migration
vendor/bin/migration generate
<?php
namespace PDOSimpleMigration\Migrations;
use PDOSimpleMigration\Library\AbstractMigration;
class Version20160128130854 extends AbstractMigration
{
public static $description = "Migration description";
public function up()
{
//$this->addSql(/*Sql instruction*/);
}
public function down()
{
//$this->addSql(/*Sql instruction*/);
}
}
Migrate to latest version
vendor/bin/migration migrate
Execute specific migration version (up or down)
vendor/bin/migration execute version --up --down
If --dump
parameter is present, migration will only dump query in screen
If you don't want to create config.php file, you can send --dsn
setup parameter.
If you send --dsn
parameter, you need to send --username
parameter too.
The prompt will ask your database password.
Directory where to save migrations classes, default migrations
Table where to store migrations versioning history, default migrations
Please report issues to Github Issue Tracker