Simple PHP migration library to use with any available PHP PDO driver.
Install this library using composer:
composer require faimmedia/migration
Use the ./vendor/bin/migrate
command to run the migrations.
Example:
./vendor/bin/migrate \
--path=migration/path \
--dsn="pgsql:host=postgres;dbname=database" \
--username=postgres
To migrate to a specific version, you may also include the --version
parameter. This will apply or undo only specific versions.
./vendor/bin/migrate \
--path=migration/path \
--dsn="pgsql:host=postgres;dbname=database" \
--username=postgres \
--version=0002
<?php
use FaimMedia\Migration\Migration;
use FaimMedia\Migration\Migration\Logger\Color;
/**
* Initialize
*/
$migration = new Migration([
'dsn' => '',
'username' => 'username',
'password' => 'my-super-secret-password',
], new Color());
/**
* Run all migrations
*/
$migration->run();
Or you can run a specific set of migrations:
Mmigrations that are already applied will be rolled back if there are -down
file present for the specific version and name.
$migration->run('0003');
Start up docker containers:
docker compose up -d
Run tests:
./bin/test
Run migration CLI:
docker compose exec -T test /app/bin/migrate --dsn=pgsql:host=postgres --username=migrate-test --path=/app/test/sql