PHPackages                             safronik/db-migrator - 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. safronik/db-migrator

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

safronik/db-migrator
====================

Check current database structure

0.1.3(2mo ago)024MITPHPPHP &gt;=8.0

Since Apr 19Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/safronik/project-db-migrator)[ Packagist](https://packagist.org/packages/safronik/db-migrator)[ Docs](https://github.com/Safronik/project-db-migrator)[ RSS](/packages/safronik-db-migrator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

safronik/db-migrator
====================

[](#safronikdb-migrator)

 **Check and change the existing SQL-schema and alters it to according requested schema**

About
=====

[](#about)

This lib helps to migrate to the given schema from the current schema.

Installation
============

[](#installation)

The preferred method of installation is via Composer. Run the following command to install the package and add it as a requirement to your project's `composer.json`:

```
composer require safronik/db-migrator
```

or just download files or clone repository (in this case you should bother about autoloader)

Usage
=====

[](#usage)

### Restrictions

[](#restrictions)

You need to do few things before usage.

- Firstly, you should implement `DBMigratorGatewayInterface` to create the gateway.

```
namespace Safronik\DBMigrator;

use Safronik\DBMigrator\Objects\Table;

interface DBMigratorGatewayInterface
{
    public function isTableExists( $table ): bool;
    public function createTable( Table $table ): bool;
    public function getTablesNames(): array;
    public function getTableColumns( string $table ): array;
    public function getTableIndexes( string $table ): array;
    public function getTableConstraints( string $table ): array;
    public function alterTable( $table, array $columns = [], array $indexes = [], array $constraints = [] ): bool;
    public function dropTable( $table ): bool;
}
```

Like this:

```
class DBMigratorGatewayInterfaceImplementation implements \Safronik\DBMigrator\DBMigratorGatewayInterface
{
    // Your implementation of the interface
}
```

- Secondly, you should make schema provider or just provide object `Schemas` to migrator object. You can use `self::getCurrentSchemas()` to get current schemas.

```
$migrator = new DBMigrator( $migrator_gateway );
$schemas  = $migrator->getCurrentSchemas();
```

Anyway, here is an example of the manual Schemas object creation:

```
$schemas = new Schemas([
    new Table(
        'example_table',

        // Columns
        [
            new Column([
                'field'   => 'id',      // Required
                'type'    => 'INT(11)', // Required
                'null'    => 'no',
                'default' => ''
                'extra'   => 'AUTO INCREMENT',
                'comment' => 'Primary key',
            ]),
            new Column([
                'field'   => 'value_field', // Required
                'type'    => 'TEXT',        // Required
                'null'    => 'yes',
                'default' => 'null',
                'extra'   => '',
                'comment' => 'Desc',
            ]),
            // ...
        ],

        // Indexes (optional)
        [
            new Index([
                'key_name' => 'PRIMARY', // Required
                'columns'  => ['id'],    // Required
                'unique'   => true,
                'type'     => 'BTREE',
                'comment'  => 'Primary key',
            ]),
            // ...
        ],

        // Constraints (optional)
        [
            new Constraint([
                'name'             => 'Example constraint', // Required
                'column'           => 'id',                 // Required
                'reference_table'  => 'examples2',          // Required
                'reference_column' => 'example_id',         // Required
                'on_update'        => '',
                'on_delete'        => '',
            ]),
            // ...
        ],
    )
]);
```

And finally after all that you can proceed:

```
$migrator = new DBMigrator(
    new DBMigratorGatewayInterfaceImplementation()
);

$migrator
    ->setSchemas( $schemas )
    ->compareWithCurrentStructure()
    ->actualizeSchema();
```

Also, you can drop existing schema:

```
$migrator = new DBMigrator(
    new DBMigratorGatewayInterfaceImplementation()
);

$migrator
    ->setSchemas( $migrator->getCurrentSchemas() )
    ->dropSchema();
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance84

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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 ~225 days

Total

4

Last Release

83d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c69e7608cd7b2fe530ef65731dc64b353ece983e732764a99d0155beac3275d9?d=identicon)[Safronik](/maintainers/Safronik)

---

Top Contributors

[![safronik](https://avatars.githubusercontent.com/u/16255344?v=4)](https://github.com/safronik "safronik (12 commits)")

---

Tags

schemamigrationdatabase

### Embed Badge

![Health badge](/badges/safronik-db-migrator/health.svg)

```
[![Health](https://phpackages.com/badges/safronik-db-migrator/health.svg)](https://phpackages.com/packages/safronik-db-migrator)
```

###  Alternatives

[odan/phinx-migrations-generator

Migration generator for Phinx

235847.8k23](/packages/odan-phinx-migrations-generator)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)[concretecms/doctrine-xml

Define database structure via XML using Doctrine data types

11100.8k2](/packages/concretecms-doctrine-xml)

PHPackages © 2026

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