PHPackages                             insolita/yii2-migration-generator - 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. insolita/yii2-migration-generator

ActiveYii2-extension[Database &amp; ORM](/categories/database)

insolita/yii2-migration-generator
=================================

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

3.2(6y ago)114483.9k—3.2%29[1 PRs](https://github.com/Insolita/yii2-migrik/pulls)5MITPHP

Since May 17Pushed 4y ago9 watchersCompare

[ Source](https://github.com/Insolita/yii2-migrik)[ Packagist](https://packagist.org/packages/insolita/yii2-migration-generator)[ RSS](/packages/insolita-yii2-migration-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (22)Used By (5)

Migration Generator
===================

[](#migration-generator)

[![Latest Stable Version](https://camo.githubusercontent.com/341bcc74d680c8504543de2557d48977eb8ff3e9c5eb8ad0350bfca4af78278b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e736f6c6974612f796969322d6d6967726174696f6e2d67656e657261746f722e737667)](https://camo.githubusercontent.com/341bcc74d680c8504543de2557d48977eb8ff3e9c5eb8ad0350bfca4af78278b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e736f6c6974612f796969322d6d6967726174696f6e2d67656e657261746f722e737667)[![Total Downloads](https://camo.githubusercontent.com/234f21d66249a41f94029f08e8e5f2dfe7bf400b7731fa9da9cce42e6142a596/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e736f6c6974612f796969322d6d6967726174696f6e2d67656e657261746f722e737667)](https://packagist.org/packages/insolita/yii2-migration-generator)[![License](https://camo.githubusercontent.com/8b6252f98ae720767c3886c88153b2afe8bcca8bca254f62f379eb7a8564fd9a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696e736f6c6974612f796969322d6d6967726174696f6e2d67656e657261746f722e737667)](https://camo.githubusercontent.com/8b6252f98ae720767c3886c88153b2afe8bcca8bca254f62f379eb7a8564fd9a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696e736f6c6974612f796969322d6d6967726174696f6e2d67656e657261746f722e737667)

- generate migration files (not dumps!) with indexes, and foreign keys, for one table, comma separated list of tables, by part of table name, for all tables by
- generate migrations based on table data - in two ways - as batchInsert Query or as insert via model
- generate migrations based on PHPDOC and model properties

### [CHANGELOG](CHANGELOG.md)

[](#changelog)

### Installation

[](#installation)

**NOTE** : Use 2.x versions for yii &lt;=2.0.13

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require --dev --prefer-dist insolita/yii2-migration-generator:~3.1

```

or add

```
"insolita/yii2-migration-generator": "~3.1"

```

to the require-dev section of your `composer.json` file.

Just install, go to gii and use (By default composer bootstrap hook)

### ANNOTATION SYNTAX

[](#annotation-syntax)

In general the syntax of column definitions is based on style of yii-migration, only separated by "|" and provide a little more opportunities for reducing code

- as you see in examples - empty brackets not necessary
- also shortcut expr() will be replaced to defaultExpression() and default() to defaultValue

You can add annotations in your model(not necessary AR or yii\\base\\Model or Object or stdClass)

`@db (db2)` - specify connection id required for migration 'db' - by default"

`@table ({{%my_table}})`- specify table for migration"

**Supported column annotations:**

- As separate annotation above class or above current variable

```
/**
* @column (name) string|notNull|default('SomeValue')
*/
```

- As addition to @property or @var definition

```
   /**
    * @var int $id @column pk()
    */
   public $id;
   /**
    * @var string $route @column string(100)|notNull()
    */
   public $route;

```

```
/**
 * @property integer    $id         @column pk|comment("Id")
 * @property string     $username   @column string(100)|unique|notNull|default("Vasya")
 * @property string     $email      @column string(200)|unique()|defaultValue("123@mail.ru")
 * @property string     $password   @column string(200)|notNull|expr(null)
 * @property string     $created_at @column string(200)|notNull|expr('CURRENT_TIMESTAMP')
 */
class TestModel extends ActiveRecord{

```

### Customizing

[](#customizing)

##### Use Own templates

[](#use-own-templates)

Copy default templates from folders

`vendor/insolita/yii2-migration-generator/gii/default_structure //schema migrations`

`vendor/insolita/yii2-migration-generator/gii/default_data //data migrations`

to some project directory, for example

`@backend/gii/templates/migrator_data;`

`@backend/gii/templates/migrator_schema;`

Change gii configuration like this

```
$config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1', 'localhost', '::1'],
    'generators' => [
        'migrik' => [
            'class' => \insolita\migrik\gii\StructureGenerator::class,
            'templates' => [
                'custom' => '@backend/gii/templates/migrator_schema',
            ],
        ],
        'migrikdata' => [
            'class' => \insolita\migrik\gii\DataGenerator::class,
            'templates' => [
                'custom' => '@backend/gii/templates/migrator_data',
            ],
        ],
    ],
];
```

##### Use own resolver for definition of columns

[](#use-own-resolver-for-definition-of-columns)

- create new class, inherited from \\insolita\\migrik\\resolver\*ColumnResolver
    - override required methods, or create methods for exclusive columns based on database types - see insolita\\migrik\\resolver\\BaseColumnResolver resolveColumn() phpdoc and realization

##### Use own resolver for definition of indexes or relations

[](#use-own-resolver-for-definition-of--indexes-or-relations)

- create new class, inherited from \\insolita\\migrik\\resolver\\TableResolver
- in bootsrap your apps add injection

`\Yii::$container->set(IMigrationTableResolver::class, YourTableResolver::class);`

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 89.8% 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 ~68 days

Recently: every ~213 days

Total

18

Last Release

2488d ago

Major Versions

1.0.0 → 2.02016-08-13

2.3 → 3.02018-06-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/40f26825f8c130796e3151e6c076721cf5bb222c42148102bb31a341a1a5c789?d=identicon)[Insolita](/maintainers/Insolita)

---

Top Contributors

[![Insolita](https://avatars.githubusercontent.com/u/1847402?v=4)](https://github.com/Insolita "Insolita (115 commits)")[![MaksimKiselev](https://avatars.githubusercontent.com/u/4495801?v=4)](https://github.com/MaksimKiselev "MaksimKiselev (5 commits)")[![githubjeka](https://avatars.githubusercontent.com/u/874234?v=4)](https://github.com/githubjeka "githubjeka (3 commits)")[![diego-mathis](https://avatars.githubusercontent.com/u/22345162?v=4)](https://github.com/diego-mathis "diego-mathis (2 commits)")[![shirase](https://avatars.githubusercontent.com/u/4026991?v=4)](https://github.com/shirase "shirase (2 commits)")[![adamzammit](https://avatars.githubusercontent.com/u/1452303?v=4)](https://github.com/adamzammit "adamzammit (1 commits)")

---

Tags

giihacktoberfestmigrationsyii2yii2-extensionyii2extension

### Embed Badge

![Health badge](/badges/insolita-yii2-migration-generator/health.svg)

```
[![Health](https://phpackages.com/badges/insolita-yii2-migration-generator/health.svg)](https://phpackages.com/packages/insolita-yii2-migration-generator)
```

###  Alternatives

[dmstr/yii2-db

Database extensions

19618.8k6](/packages/dmstr-yii2-db)[sjaakp/yii2-spatial

Yii2 ActiveRecord supporting MySQL spatial data

1873.8k1](/packages/sjaakp-yii2-spatial)

PHPackages © 2026

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