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

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

marekskopal/orm-migrations
==========================

Migrations for MarekSkopal ORM.

v1.0.0(2mo ago)0325—0%MITPHPPHP &gt;=8.4

Since Dec 31Pushed 2mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (9)Versions (5)Used By (0)

ORM Migrations
==============

[](#orm-migrations)

Database migration library for [marekskopal/orm](https://github.com/marekskopal/orm). Automatically generates PHP migration files by comparing your ORM entity schema with the live database schema.

Supports **MySQL** and **PostgreSQL**.

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

[](#installation)

```
composer require marekskopal/orm-migrations
```

Usage
-----

[](#usage)

### Setup

[](#setup)

```
use MarekSkopal\ORM\Database\MySqlDatabase;
use MarekSkopal\ORM\Migrations\Migrator;
use MarekSkopal\ORM\Schema\Builder\SchemaBuilder;

$database = new MySqlDatabase(host: 'localhost', username: 'root', password: 'password', database: 'mydb');

$schema = (new SchemaBuilder())
    ->addEntityPath(__DIR__ . '/Entity')
    ->build();

$migrator = new Migrator(
    path: __DIR__ . '/migrations/',
    database: $database,
);
```

For PostgreSQL, use `PostgresDatabase` instead of `MySqlDatabase` — no other changes needed.

An optional PSR-3 `LoggerInterface` can be passed as the third argument to `Migrator` to log migration execution.

### Generate a migration

[](#generate-a-migration)

```
$migrator->generate(schema: $schema, name: 'CreateUserTable', namespace: 'App\Migrations');
```

This compares the ORM entity schema against the live database and writes a new PHP migration file to the configured path. Only actual differences (added/changed/removed tables, columns, indexes, foreign keys) are included.

Example generated file:

```
