PHPackages                             kuaukutsu/poc-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. kuaukutsu/poc-migration

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

kuaukutsu/poc-migration
=======================

Proof of Concept: Database migration

0.6.4(3mo ago)1136MITPHPPHP ^8.3

Since Dec 24Pushed 3mo agoCompare

[ Source](https://github.com/kuaukutsu/poc-migration)[ Packagist](https://packagist.org/packages/kuaukutsu/poc-migration)[ RSS](/packages/kuaukutsu-poc-migration/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (38)Versions (24)Used By (0)

Proof of Concept: Database Migrator
===================================

[](#proof-of-concept-database-migrator)

[![PHP Version Require](https://camo.githubusercontent.com/e59bd04b09583a360ef2780a84a5ea1d5fbb10c90821de1bec9c6e6026466a35/687474703a2f2f706f7365722e707567782e6f72672f6b7561756b757473752f706f632d6d6967726174696f6e2f726571756972652f706870)](https://packagist.org/packages/kuaukutsu/poc-migration)[![Latest Stable Version](https://camo.githubusercontent.com/15e747b8a0c0623989682f33b01066a3831b3820f2968474eb5957d792d25930/68747470733a2f2f706f7365722e707567782e6f72672f6b7561756b757473752f706f632d6d6967726174696f6e2f762f737461626c65)](https://packagist.org/packages/kuaukutsu/poc-migration)[![License](https://camo.githubusercontent.com/f7d0ac886f2fec98510ff5b4a8c269e860111e4e233201076d657b8cea62a871/687474703a2f2f706f7365722e707567782e6f72672f6b7561756b757473752f706f632d6d6967726174696f6e2f6c6963656e7365)](https://packagist.org/packages/kuaukutsu/poc-migration)[![Psalm Level](https://camo.githubusercontent.com/65b95e46461fab52a18c5cb132480e7ecaf176267216e99c34bca88d1dc9bda5/68747470733a2f2f73686570686572642e6465762f6769746875622f6b7561756b757473752f706f632d6d6967726174696f6e2f6c6576656c2e737667)](https://shepherd.dev/github/kuaukutsu/poc-migration)[![Psalm Type Coverage](https://camo.githubusercontent.com/43fd5957cb1ba7846a04a1f10113a724a17b95daa5b6ee353c77e8c1e4114c1b/68747470733a2f2f73686570686572642e6465762f6769746875622f6b7561756b757473752f706f632d6d6967726174696f6e2f636f7665726167652e737667)](https://shepherd.dev/github/kuaukutsu/poc-migration)[![Mutation testing badge](https://camo.githubusercontent.com/a2e232f175c48cee9508f43fffb932c07fc2d70241969346b91b34a20aa626e7/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532466b7561756b75747375253246706f632d6d6967726174696f6e2532466d61696e)](https://dashboard.stryker-mutator.io/reports/github.com/kuaukutsu/poc-migration/main)

Консольная программа для управления миграциями.

### Command

[](#command)

- **init** — инициализация проекта: создание папки для миграций и конфигурационного файла.
- **up** — применение всех ожидающих миграций до самой свежей.
- **down** — откат последней примененной миграции (или нескольких).
- **fixture** — применение всех фикстур.
- **create** — создание файла миграции (удобно при разработке).
- **verify** — последовательный запуск up и сразу down для последней версии миграций (удобно при разработке).
- **redo** — последовательный запуск down и сразу up для последней миграции (удобно при разработке).

### setup

[](#setup)

Например, для базы данных с именем *main* под управлением сервера **postgres**:

```
mkdir -p ./migration/pgsql/{main,main-fixture}
```

Описываем конфигурацию:

```
$migrator = new Migrator(
    collection: new MigrationCollection(
        new Migration(
            path: __DIR__ . '/migration/postgres/main',
            driver: new PdoDriver(
                dsn: 'pgsql:host=postgres;port=5432;dbname=main',
                username: 'postgres',
                password: 'postgres',
            )
        )
    ),
);
```

### migration

[](#migration)

Команды миграции описываются на языке SQL, например:

```
-- @up
CREATE TABLE IF NOT EXISTS public.entity (
    id serial NOT NULL,
    parent_id integer NOT NULL,
    created_at timestamp(0) DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp(0) DEFAULT CURRENT_TIMESTAMP NOT NULL,
    CONSTRAINT entity_pkey PRIMARY KEY (id)
);
CREATE INDEX IF NOT EXISTS "I_entity_parent_id" ON public.entity USING btree (parent_id);

-- @down
DROP INDEX IF EXISTS I_entity_parent_id;
DROP TABLE IF EXISTS public.entity;
```

Управляющие команды:

- `@up`
- `@down`
- `@skip`

Если команды не указаны, то весь код будет вычитан как секция `up`.
Если нужно скипнуть файл целиком, то можно добавить в название постфикс `skip`, например `202501011025_name_skip.sql`

### CLI application

[](#cli-application)

```
use DI\Container;
use kuaukutsu\poc\migration\internal\connection\PDO\Driver;
use kuaukutsu\poc\migration\example\presentation\DownCommand;
use kuaukutsu\poc\migration\example\presentation\CreateCommand;
use kuaukutsu\poc\migration\example\presentation\FixtureCommand;
use kuaukutsu\poc\migration\example\presentation\VerifyCommand;
use kuaukutsu\poc\migration\example\presentation\InitCommand;
use kuaukutsu\poc\migration\example\presentation\RedoCommand;
use kuaukutsu\poc\migration\example\presentation\UpCommand;
use kuaukutsu\poc\migration\tools\PrettyConsoleOutput;
use kuaukutsu\poc\migration\Migration;
use kuaukutsu\poc\migration\MigrationCollection;
use kuaukutsu\poc\migration\Migrator;
use kuaukutsu\poc\migration\MigratorInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;

require dirname(__DIR__) . '/vendor/autoload.php';

$container = new Container(
    [
        Migrator::class => factory(
            fn(): Migrator => new Migrator(
                collection: new MigrationCollection(
                    new Migration(
                        path: __DIR__ . '/migration/sqlite/db',
                        driver: new Driver(
                            dsn: 'sqlite:' . __DIR__ . '/data/sqlite/db.sqlite3',
                        )
                    )
                ),
                eventSubscribers: [
                    new PrettyConsoleOutput(),
                ],
            )
        ),
    ]
);

$console = new Application();
$console->setCommandLoader(
    new ContainerCommandLoader(
        $container,
        [
            'migrate:init' => InitCommand::class,
            'migrate:up' => UpCommand::class,
            'migrate:down' => DownCommand::class,
            'migrate:redo' => RedoCommand::class,
            'migrate:verify' => VerifyCommand::class,
            'migrate:fixture' => FixtureCommand::class,
            'migrate:create' => CreateCommand::class,
        ],
    )
);

try {
    exit($console->run());
} catch (Exception $e) {
    exit(Command::FAILURE);
}
```

### Example

[](#example)

```
make app
```

```
/example $ php cli.php migrate:init
[sqlite/db] initialization: setup.sql done

/example $ php cli.php migrate:up
[sqlite/db] up: 202501011024_entity_create.sql done
[sqlite/db] up: 202501021024_account_create.sql done
[sqlite/db] up: 202501021025_account_email.sql done

/example $ php cli.php migrate:down
[sqlite/db] down: 202501021025_account_email.sql done
[sqlite/db] down: 202501021024_account_create.sql done
[sqlite/db] down: 202501011024_entity_create.sql done
```

#### With exactly all

[](#with-exactly-all)

If any migration fails, the entire batch is rolled back, leaving the database unchanged.

```
/example $ php cli.php migrate:up --exactly-all
[sqlite/db] up: 202501011024_entity_create.sql done
[sqlite/db] up: 202501021024_account_create.sql done
[sqlite/db] up: 202501021025_account_email.sql done
```

#### With repeatable

[](#with-repeatable)

```
/example $ php cli.php migrate:up --with-repeatable
[sqlite/db] up: 202501011024_entity_create.sql done
[sqlite/db] up: 202501021024_account_create.sql done
[sqlite/db] up: 202501021025_account_email.sql done
[sqlite/db] repeatable: 202501011024_entity_correction.sql done
[sqlite/db] repeatable: 202501011024_entity_correction_2.sql done
```

#### Down with latest version

[](#down-with-latest-version)

```
/example $ php cli.php migrate:up --limit=1
[sqlite/db] up: 202501011024_entity_create.sql, vers: 1772723563954 done

/example $ php cli.php migrate:up --limit=2
[sqlite/db] up: 202501021024_account_create.sql, vers: 1772723566084 done
[sqlite/db] up: 202501021025_account_email.sql, vers: 1772723566084 done

/example $ php cli.php migrate:down --latest-version
[sqlite/db] down: 202501021025_account_email.sql, vers: 1772723566084 done
[sqlite/db] down: 202501021024_account_create.sql, vers: 1772723566084 done
```

#### Redo with latest version

[](#redo-with-latest-version)

```
/example $ php cli.php migrate:up
[sqlite/db] up: 202501021024_account_create.sql, vers: 1772723718828 done
[sqlite/db] up: 202501021025_account_email.sql, vers: 1772723718828 done

/example $ php cli.php migrate:redo --latest-version
[sqlite/db] down: 202501021025_account_email.sql, vers: 1772723718828 done
[sqlite/db] down: 202501021024_account_create.sql, vers: 1772723718828 done
[sqlite/db] up: 202501021024_account_create.sql, vers: 1772723727397 done
[sqlite/db] up: 202501021025_account_email.sql, vers: 1772723727397 done
```

#### Verify

[](#verify)

```
/example $ php cli.php migrate:create test --db=sqlite/db
/example $ php cli.php migrate:create test2 --db=sqlite/db
/example $ php cli.php migrate:create test3 --db=sqlite/db

/example $ php cli.php migrate:verify
[sqlite/db] up: 202603070850_test.sql, vers: 177287432696 done
[sqlite/db] up: 202603070850_test2.sql, vers: 177287432696 done
[sqlite/db] up: 202603070850_test3.sql, vers: 177287432696 done
[sqlite/db] down: 202603070850_test3.sql, vers: 177287432696 done
[sqlite/db] down: 202603070850_test2.sql, vers: 177287432696 done
[sqlite/db] down: 202603070850_test.sql, vers: 177287432696 done
```

**With limit**

```
/example $ php cli.php migrate:verify --limit=1
[sqlite/db] up: 202603070850_test.sql, vers: 177287441498 done
[sqlite/db] down: 202603070850_test.sql, vers: 177287441498 done
```

**error**

```
/example $ php cli.php migrate:verify
[sqlite/db] up: 202603070850_test.sql, vers: 177287479980 done
[sqlite/db] up: 202603070850_test2.sql error
SQLSTATE[HY000]: General error: 1 incomplete input
-- SQL CODE
INSERT INTO ededede

[sqlite/db] down: 202603070850_test.sql, vers: 177287479980 done
202603070850_test2.sql: SQLSTATE[HY000]: General error: 1 incomplete input
```

### Static analysis

[](#static-analysis)

To run static analysis:

```
make check
```

### Unit testing

[](#unit-testing)

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

```
make tests
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance81

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

21

Last Release

99d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/647093?v=4)[Dmitriy Krivopalov](/maintainers/kuaukutsu)[@kuaukutsu](https://github.com/kuaukutsu)

---

Top Contributors

[![kuaukutsu](https://avatars.githubusercontent.com/u/647093?v=4)](https://github.com/kuaukutsu "kuaukutsu (43 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kuaukutsu-poc-migration/health.svg)

```
[![Health](https://phpackages.com/badges/kuaukutsu-poc-migration/health.svg)](https://phpackages.com/packages/kuaukutsu-poc-migration)
```

###  Alternatives

[getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

15.6k86.4k1](/packages/getgrav-grav)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
