Skip to content

Simple PHP migration library to use with any available PHP PDO driver

Notifications You must be signed in to change notification settings

FaimMedia/php-migration

Repository files navigation

FaimMedia PHP Migration

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

About

Simple PHP migration library to use with any available PHP PDO driver

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages