PHPackages                             allenjb/migrationmanager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. allenjb/migrationmanager

ActiveLibrary[Database &amp; ORM](/categories/database)

allenjb/migrationmanager
========================

A simple, framework agnostic, MySQL non-reversible migrations library that accepts a pre-configured PDO connection

2.0.4(7y ago)124MITPHPPHP ~7.1

Since Mar 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/AllenJB/MigrationManager)[ Packagist](https://packagist.org/packages/allenjb/migrationmanager)[ Docs](https://github.com/AllenJB/MigrationManager)[ RSS](/packages/allenjb-migrationmanager/feed)WikiDiscussions v2 Synced 2mo ago

READMEChangelog (9)DependenciesVersions (12)Used By (0)

MigrationManager
================

[](#migrationmanager)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1a0dc2517647fbc11a84e040bd0f85cacc27f12bcc4feabd8a530a167f739d6f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f416c6c656e4a422f4d6967726174696f6e4d616e616765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/AllenJB/MigrationManager)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

A simple, framework agnostic, MySQL non-reversible migrations library that accepts a pre-configured PDO connection (allowing you to preset desired connection configuration such as sql\_mode or timezone and your own error handling).

Why? I looked at other libraries for migrations but they all had a large number of issues around MySQL language support and reversals, or controlling the mysql connection (eg. timezone, sql\_mode) is problematic because they control creation of the connection. While I could try to enforce not using the problematic features, it's much easier if they aren't available in the first place.

Versions
--------

[](#versions)

Use version 1 for compatibility with PHP 5.6. Version 2+ require PHP 7.1+

Install
-------

[](#install)

Via Composer

```
$ composer require allenjb/migrationmanager
```

Usage
-----

[](#usage)

```
$pdo = new \PDO(...);
$pathToMigrations = "../db/migrations/";
$migrationsTable = 'migrations';
$manager = new AllenJB\MigrationManager($pdo, $pathToMigrations, $migrationsTable);

// List migrations
print_r ($manager->executedMigrations());
print_r ($manager->migrationsToExecute());
print_r ($manager->futureMigrations());

// Perform pending migrations
$manager->executeMigrations();

// You MUST call when you've finished using the manager to release all locks
$manager->unlock();
```

Migration Files
---------------

[](#migration-files)

Filenames MUST be in the format YYYYMMDD\_HHmm\_ClassName.php

Time is in 24 hour format.

ClassName must be unique.

If the date is greater than today (disregarding time), then the migration will not be executed until that date. This allows you to schedule migrations in the future (for example, you're removing a field but want to leave it in the database for a period to guard against dataloss / code rollbacks).

```
