PHPackages                             enlivenapp/migrations - 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. enlivenapp/migrations

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

enlivenapp/migrations
=====================

Database migrations and seeds for modular PHP applications

0.2.1(2mo ago)0611MITPHPPHP &gt;=8.1

Since Apr 23Pushed 2mo agoCompare

[ Source](https://github.com/enlivenapp/Migrations)[ Packagist](https://packagist.org/packages/enlivenapp/migrations)[ RSS](/packages/enlivenapp-migrations/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (6)Used By (11)

[![Stable? Not Quite Yet](https://camo.githubusercontent.com/8712c441bb32fd8db507e0008c5d13e30def50064f8fcbc689fbcf5191f7d2af/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737461626c652533462d6e6f7425323071756974652532307965742d626c75653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/enlivenapp/migrations)[![License](https://camo.githubusercontent.com/135fd2d85733bcb5a020dad17c9cf2bde5ead88872e429764134bbd0b6cc3cf6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f656e6c6976656e6170702f6d6967726174696f6e733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/enlivenapp/migrations)[![PHP Version](https://camo.githubusercontent.com/f60e585182de01060f394dd18ea8b32648bcd80806a0e5052e472bbb3ee96c51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f656e6c6976656e6170702f6d6967726174696f6e733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/enlivenapp/migrations)[![Monthly Downloads](https://camo.githubusercontent.com/e8b8ded072fe7d9a16c8e95de6b48b185f5b3dc8197458ad9b324fbf3f083363/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f656e6c6976656e6170702f6d6967726174696f6e733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/enlivenapp/migrations)[![Total Downloads](https://camo.githubusercontent.com/b3516d9e4720cfbe137cb99cbd693059e81bd869d919314b37cc64da582ee491/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e6c6976656e6170702f6d6967726174696f6e733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/enlivenapp/migrations)[![GitHub Issues](https://camo.githubusercontent.com/f366f288345671950e3c6df63d0d8c0618514812098b059d5ee550fe82cd85e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f656e6c6976656e6170702f4d6967726174696f6e733f7374796c653d666f722d7468652d6261646765)](https://github.com/enlivenapp/Migrations/issues)[![Contributors](https://camo.githubusercontent.com/e983bd31d9fb067483cd679ae85b1a5f02fe6a0de4d70d6cf3c9964eb7223047/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f656e6c6976656e6170702f4d6967726174696f6e733f7374796c653d666f722d7468652d6261646765)](https://github.com/enlivenapp/Migrations/graphs/contributors)[![Latest Release](https://camo.githubusercontent.com/eed3dcc09adc5474dd37a10b4827586a4f42f0cf52edb6ddc5de821cd43e9363/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f656e6c6976656e6170702f4d6967726174696f6e733f7374796c653d666f722d7468652d6261646765)](https://github.com/enlivenapp/Migrations/releases)[![Contributions Welcome](https://camo.githubusercontent.com/9db3f8b82ea88469efd296a9305fc00f40b4c9450bb6b539d42d339fa6963444/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6e747269627574696f6e732d77656c636f6d652d626c75653f7374796c653d666f722d7468652d6261646765)](https://github.com/enlivenapp/Migrations/pulls)

Migrations Library
==================

[](#migrations-library)

**I noticed folks downloading some of these packages. I'm super grateful, Thank You! I would like to let folks know until this notice disappears I'm doing a lot of breaking changes without worrying about them. Once versions are up around 0.5.x things should settle down.**

Migrations is a single-package standalone PHP library for database migrations and seeds with minimal requirements. It tracks changes applied to your database and runs new ones in order. No framework required, just a database connection. MySQL and MariaDB supported currently. Optional CLI support is available through the `flightphp/runway` CLI.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1 with `ext-pdo` and `ext-pdo_mysql`
- MySQL or MariaDB
- `composer/semver` ^3.0

Recommended:
------------

[](#recommended)

- `flightphp/runway`
- `enlivenapp/flight-school`

Data Saver
----------

[](#data-saver)

The data saver automatically attempts to protect every migration against partial failure. Non-destructive changes are repaired by running the opposite operation. For destructive changes, tables are temporaily copied before the operation. If the migration fails, everything is reverted to the pre-migration state.

#### Quick notes:

[](#quick-notes)

- to use command line functionality, you'll need to `require flightphp/runway`, otherwise you'll only have programatic access.
- versions differences are derived from composer/installed,json and the seeds table in the database.

> If you're familiar with Phinx/CakePHP you'll find the fluent chain very familiar. Codeingiter and Sympony users will find these fairly intuitive. Laravel... o\_0 :D

> PRs and contributions are welcome.

#### Supported Frameworks

[](#supported-frameworks)

- FlightPHP

Install
-------

[](#install)

```
composer require enlivenapp/migrations
```

Full functionality:

```
composer require flightphp/runway
```

Default Paths/Settings
----------------------

[](#default-pathssettings)

By default Migrations look in:

```
    'vendor/*/*/src/Database/Migrations',
    'plugins/*/Database/Migrations',
```

and seeds expects a return array from:

```
    'vendor/*/*/src/Database/Seeds',
    'plugins/*/Database/Seeds',
```

Configuration
-------------

[](#configuration)

Migrations uses the first database connection and associated migration array found first. It does not continue looking after it finds a database connection.

The order in which Migrations searches:

**FlightPHP** installed (checked first): `Flight::set('db')`, `Flight::set('migrations')`(see example below)

Migrations checks: `Flight::get('db')` is checked for a PDO database connection, if found `Flight::get('migrations')` is checked and stops look for Migrations config options.

**File Location Configuration**

Create `migrations.php` file in `config/` or `app/config/` that returns an array with only the keys you want to change. Defaults are in `src/Config/Config.php`.

- `app/config/migrations.php` (checked 2nd)(skeleton/general app layout)
- `config/migrations.php` (checked 3rd)(project root)

```
// database.php
return [
    // database connection
    'host'     => 'localhost',
    'dbname'   => 'myapp',
    'user'     => 'root',
    'password' => '',
    // below is optional
    'port'     => 3306,
    'charset'  => 'utf8mb4',
    // the key we look for to override default settings
    'migrations' => [
        // set folders to look in (recursive)
        'paths' => [
            'vendor/*/*/src/Database/Migrations',
            'plugins/*/Database/Migrations',
        ],
        // if you place a seed file in a different location
        // you can add it to the override. File must be 'Seed.php'
        'seeds' => [
            // set folders to look in (recursive)
            'paths'  => [
                'vendor/*/*/src/Database/Seeds',
                'plugins/*/Database/Seeds',
            //  'your/path/to/Seeds'
            ],
        ],
    ],
];
```

*Important Notes:*

- If a database connection is not found, Migrations will throw an exception.

### Manual Use

[](#manual-use)

You can set the database connection and config settings on migrations at runtime.

Setting Up Migrations
---------------------

[](#setting-up-migrations)

```
// Using default configuration
$migrate = new \Enlivenapp\Migrations\Services\MigrationSetup();

// With configuration overrides (only include the keys you want to change)
$config = [
    'migrations' => [
        // set folders to look in (recursive)
        'paths' => [
            'vendor/*/*/src/Database/Migrations',
            'plugins/*/Database/Migrations',
        ],
        // seed overrides
        'seeds' => [
            'paths'  => [
                'vendor/*/*/src/Database/Seeds',
                'plugins/*/Database/Seeds',
            ],
        ],
    ],
];

// attempts to use database and default config
$migrate = new \Enlivenapp\Migrations\Services\MigrationSetup();

// pre php 8+ (null because the db connection is handled elsewhere)
$migrate = new \Enlivenapp\Migrations\Services\MigrationSetup(null, $config);

// php8+ introduced named arguments (allows skipping null in the first arg)
$migrate = new \Enlivenapp\Migrations\Services\MigrationSetup(config: $config);

// Or pass your own connection and/or config directly
$pdo    = new PDO('mysql:host=localhost;dbname=myapp;charset=utf8mb4', 'user', 'pass');
$migrate = new \Enlivenapp\Migrations\Services\MigrationSetup($pdo);
$migrate = new \Enlivenapp\Migrations\Services\MigrationSetup($pdo, $config);
```

Quick Migration file example
----------------------------

[](#quick-migration-file-example)

```
// vendor/acme/blog/src/Database/Migrations/2026-01-15-143022_CreatePostsTable.php
