faimmedia / migration
FaimMedia Simple PHP Database Migration
0.2
2024-06-09 12:26 UTC
Requires
- php: ^8.2
- ext-pdo: *
Requires (Dev)
- ext-pdo_pgsql: *
- ext-pgsql: *
- phpunit/phpunit: ^10.3
This package is auto-updated.
Last update: 2025-03-09 13:58:38 UTC
README
Simple PHP migration library to use with any available PHP PDO driver.
Install & usage
Add composer
Install this library using composer:
composer require faimmedia/migration
Run migrations (using CLI)
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
Run migrations (from PHP)
<?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');
Development
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