PHPackages                             peptolab/phpdb-migration - 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. peptolab/phpdb-migration

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

peptolab/phpdb-migration
========================

Idempotent database migration engine for php-db/phpdb.

v0.1.1-alpha(2mo ago)022↓66.7%BSD-3-ClausePHPPHP ^8.3CI failing

Since Feb 23Pushed 2mo agoCompare

[ Source](https://github.com/peptolab/phpdb-migration)[ Packagist](https://packagist.org/packages/peptolab/phpdb-migration)[ Docs](https://github.com/peptolab/phpdb-migration)[ Fund](https://ko-fi.com/peptolab)[ RSS](/packages/peptolab-phpdb-migration/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (3)Used By (0)

phpdb-migration
===============

[](#phpdb-migration)

Idempotent database migration engine for [php-db/phpdb](https://github.com/php-db/phpdb).

Features
--------

[](#features)

- **Idempotent migrations** - Safe to run multiple times; operations check schema state before executing
- **Definition mismatch detection** - Compare existing schema against desired definitions with configurable strategies (ignore, report, alter)
- **Rich helper methods** - `ensureTable()`, `ensureColumn()`, `ensureIndex()`, `ensureForeignKey()`, `ensureUniqueKey()`, and more
- **Dry-run preview** - See what SQL would execute without making changes
- **CLI commands** - `db:migrate` and `db:migrate:create` via Symfony Console
- **Laminas/Mezzio integration** - ConfigProvider for container-based setup with laminas-cli

Installation
------------

[](#installation)

```
composer require peptolab/phpdb-migration
```

Quick Start
-----------

[](#quick-start)

### Standalone Usage

[](#standalone-usage)

```
use PhpDb\Adapter\Adapter;
use PhpDb\Migration\MigrationRunner;
use PhpDb\Migration\MismatchStrategy;

$adapter = new Adapter([
    'driver'   => 'Pdo_Mysql',
    'database' => 'mydb',
    'username' => 'root',
    'password' => '',
]);

$runner = new MigrationRunner(
    adapter: $adapter,
    migrationsPath: __DIR__ . '/data/migrations',
    migrationsNamespace: 'MyApp\\Migrations',
    mismatchStrategy: MismatchStrategy::Report,
);

$runner->ensureMigrationsTable();
$results = $runner->runPending();
```

### Laminas/Mezzio Integration

[](#laminasmezzio-integration)

The package auto-registers via the `ConfigProvider`. Add your configuration:

```
// config/autoload/migrations.global.php
use PhpDb\Migration\MismatchStrategy;

return [
    'phpdb-migration' => [
        'migrations_path'      => getcwd() . '/data/migrations',
        'migrations_namespace' => 'Data\\Migration',
        'adapter_service'      => \PhpDb\Adapter\AdapterInterface::class,
        'resolution'           => MismatchStrategy::Report,
    ],
];
```

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

[](#configuration)

KeyTypeDefaultDescription`migrations_path``string``getcwd() . '/data/migrations'`Directory containing migration files`migrations_namespace``string``App\Migration`PSR-4 namespace of migration classes`adapter_service``string``PhpDb\Adapter\AdapterInterface`Container service name for the adapter`resolution``MismatchStrategy|string``MismatchStrategy::Report`How to handle definition mismatchesWriting Migrations
------------------

[](#writing-migrations)

Create a migration class that extends `AbstractMigration`:

```
