Abstract migration engine for any database.
At first, you should create config file with command:
vendor/bin/migration init
Or you can create and edit migration.php file manually. Example config:
<?php
use Veejay\Migration\Repository\SqlRepository;
return [
'path' => __DIR__ . '/migration',
'repository' => new SqlRepository(
'mysql:host=localhost;dbname=database',
'root',
'password',
null,
SqlRepository::MIGRATION_TABLE,
),
];Next command will create new migration file with name like m_000000_000000_my_1st_migration.
vendor/bin/migration create my_1st_migration
Then you should edit up() and down() methods according to your purposes.
<?php
declare(strict_types=1);
use Veejay\Migration\Unit\Migration;
final class m_000000_000000_my_1st_migration extends Migration
{
public function up(): bool
{
$repository = $this->getRepository(); /* @var SqlRepository $repository */
$sql = 'CREATE TABLE `test` (`id` INT AUTO_INCREMENT, `name` TEXT, PRIMARY KEY (`id`) USING BTREE)';
return $repository->getDb()->execute($sql);
}
public function down(): bool
{
$repository = $this->getRepository(); /* @var SqlRepository $repository */
$sql = 'DROP TABLE `test`';
return $repository->getDb()->execute($sql);
}
}Apply all migrations.
vendor/bin/migration migrate
Apply/revert to specific migration.
vendor/bin/migration migrate name_part
Print migration history.
vendor/bin/migration history
You can write your own wrapper for any DB. Just implement Veejay\Migration\Repository\RepositoryInterface and use any storage you want.
- PHP 8.0+
composer require "veejay/migration"