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

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

demmonico/yii2-migration
========================

Yii2 Migration class

v1.0.0(9y ago)01321MITPHPPHP &gt;5.5.0

Since Nov 16Pushed 9y ago2 watchersCompare

[ Source](https://github.com/demmonico/yii2-migration)[ Packagist](https://packagist.org/packages/demmonico/yii2-migration)[ Docs](https://github.com/demmonico/yii2-migration)[ RSS](/packages/demmonico-yii2-migration/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

\#Yii2 migration class ##Description Yii2 class Migration provide more flexibility usage interface then basic Yii2 class, so can be used instead of it. It is backward compatible with basic migration class.

\##Usage

This is a sample of some migration with new interface.

```
class m000000_000000_tbl_country extends Migration
{
    // common table's info
    protected $tableName = '{{%country}}';
    //
    //
    // structure table's info
    protected $columns = [
        'code'                      => 'CHAR(2) NOT NULL PRIMARY KEY comment "ISO 3166-1 alpha-2"',
        self::COLUMN_NAME           => 'VARCHAR(255) NOT NULL',
        'phone_country'             => 'VARCHAR(10) NOT NULL',
        'language'                  => 'CHAR(2) DEFAULT NULL comment "ISO 639-1"',
        'currency'                  => 'CHAR(3) DEFAULT NULL comment "ISO 4217"',
        self::COLUMN_ISACTIVE       => 'TINYINT(1) UNSIGNED NOT NULL DEFAULT '.self::BOOL_ON,
        self::COLUMN_ORDER          => 'INT(11) UNSIGNED NOT NULL DEFAULT 1000',
        self::COLUMN_CREATED        => 'DATETIME NOT NULL',
        self::COLUMN_UPDATED        => 'DATETIME DEFAULT NULL',
    ];
    //
    protected $indexKeys = [self::COLUMN_ISACTIVE, self::COLUMN_ORDER, 'phone_country', 'currency'];
    //
    protected $foreignKeys = [
        'language' => [
            'refTable' => self::TABLE_LANGUAGE,
            'refColumn'=>'code',
        ],
    ];
    //
    //
    // common table's info
    protected $insertColumns = [
        'code',
        self::COLUMN_NAME,
        'phone_country',
        'language',
        'currency',
        self::COLUMN_CREATED,
        self::COLUMN_UPDATED,
    ];
    //
    protected $insertRows = [
        ['UK',  'United Kingdom',   '44',   'EN', 'GBP'],
        ['USA', 'United States',    '1',    'EN', 'USD'],
        ['UA',  'Ukraine',          '380',  'RU', 'UAH'],
    ];

}
```

\###Properties

- `$tableName` is a table name. REQUIRED property. You can use constants instead (see below).
- `$columns` is a list of columns. REQUIRED property. 'Created' and 'Updated' columns will be added automatically.
- `$indexKeys` is a list of index keys. Use simple array if you want create simple index or use associative key (`'phone_country' => true`) if you need to create unique key.
- `$foreignKeys` is a list of foreign keys. Use simple array like `foreignKeyThisTable => relatedTableName` to create relation with column named `id` in related table or you can use associative array instead.
- `$insertColumns` is a list of columns of insertion. Use it if you want insert some default data immediate after table creation.
- `$insertRows` is a list of rows of insertion. Use it if you want insert some default data immediate after table creation.

You can use also some map interface to store table names in one place and use constants like self::TABLE\_NAME

```
class m000000_000000_tbl_country extends Migration implements DbMapInterface
{
    // common table's info
    protected $tableName = self::TABLE_COUNTRY;
}
```

Also you can tune other options like:

- `$tableOptions`
- `$isAutoAppendDateTime`
- `$insertSingleColumnName`
- `$insertCreatedColumnName`
- `$insertUpdatedColumnName`
- `$insertStatusUpdatedColumnName`

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3513d ago

### Community

Maintainers

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

---

Top Contributors

[![demmonico](https://avatars.githubusercontent.com/u/10497315?v=4)](https://github.com/demmonico "demmonico (2 commits)")

---

Tags

migrationyii2extensionyiicomponent

### Embed Badge

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

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

###  Alternatives

[dmstr/yii2-migrate-command

Console Migration Command with multiple paths/aliases support

31297.1k6](/packages/dmstr-yii2-migrate-command)[sjaakp/yii2-sortable-behavior

Sort ActiveRecords and related records in Yii2.

36162.8k](/packages/sjaakp-yii2-sortable-behavior)[c006/yii2-migration-utility

Automatically writes the create tables for migrations or create tables in general

63161.8k4](/packages/c006-yii2-migration-utility)[sjaakp/yii2-spatial

Yii2 ActiveRecord supporting MySQL spatial data

1877.2k1](/packages/sjaakp-yii2-spatial)[nanson/yii2-postgis

Yii2-extension to work with postgis data

1852.9k](/packages/nanson-yii2-postgis)[mg-code/yii2-helpers

A collection of useful helper classes for Yii framework 2.0

2023.1k5](/packages/mg-code-yii2-helpers)

PHPackages © 2026

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