PHPackages                             tecnocen/yii2-migrate - 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. [Framework](/categories/framework)
4. /
5. tecnocen/yii2-migrate

ActiveLibrary[Framework](/categories/framework)

tecnocen/yii2-migrate
=====================

Yii 2 Library to handle normalized table creation

1.0.2(8y ago)115.4k1[1 issues](https://github.com/tecnocen-com/yii2-migrate/issues)3BSD-3-ClausePHPPHP &gt;=5.5

Since Apr 27Pushed 8y ago2 watchersCompare

[ Source](https://github.com/tecnocen-com/yii2-migrate)[ Packagist](https://packagist.org/packages/tecnocen/yii2-migrate)[ RSS](/packages/tecnocen-yii2-migrate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (3)

Yii2 Migrate Tools
==================

[](#yii2-migrate-tools)

This library eases the creation of normalized databases by providing classes to create tables separatedly with a simple logic.

Instalation
-----------

[](#instalation)

You can use composer to install the library `tecnocen/migrate` by running the command;

`composer require tecnocen/migrate`

or edit the `composer.json` file

```
require: {
    "tecnocen/yii2-migrate": "*",
}
```

Usage
-----

[](#usage)

### Create Table Migrations

[](#create-table-migrations)

You can use the `tecnocen\migrate\CreateTableMigration` to generate different type of migration tables to be used by each of your table types.

For example lets say you want to save who and when edits and creates each the entities on your system but your pivot tables only require to know when they were created since they can't be edited.

```
abstract class EntityTable extends \tecnocen\migrate\CreateTableMigration
{
    public function defaultColumns()
    {
        return [
            'created_at' => $this->datetime()->notNull(),
            'updated_at' => $this->datetime()->notNull(),
            'created_by' => $this->normalKey(),
            'updated_by' => $this->normalKey(),
        ]
    }

    public function defaultForeignKeys()
    {
        return [
            'created_by' => 'user',
            'updated_by' => 'user',
        ];
    }
}

abstract class PivotTable extends \tecnocen\migrate\CreateTableMigration
{
    public function defaultColumns()
    {
        return [
            'created_at' => $this->datetime()->notNull(),
        ]
    }
}
```

Then you can use them separatedly for each type of table you have

```
class m170101_010101_ticket extends EntityTable
{
     public function columns()
     {
         return [
             'id' => $this->primaryKey(),
             'project_id' => $this->normalKey(),
             'title' => $this->string(150)->notNull(),
             'description' => $this->text(),
         ];
     }

     public function foreignKeys()
     {
         return ['project_id' => ['table' => 'project']];
     }
}

class m17010101_010102_ticket_employee extends PivotTable
{
     public function columns()
     {
         return [
             'ticket_id' => $this->normalKey(),
             'employee_id' => $this->normalKey(),
         ];
     }

     public function foreignKeys()
     {
         return [
             'ticket_id' => ['table' => 'ticket'],
             'employee_id' => ['table' => 'employee'],
         ];
     }

     public function compositePrimaryKeys()
     {
         return ['ticket_id', 'employee_id'];
     }
}
```

When running the migration `m170101_010101_ticket` it will generate a table with the columns

- `id`,
- `project_id`,
- `title`,
- `description`,
- `created_by`,
- `updated_by`
- `created_at`,
- `updated_at`

With primary key `id` and three foreign keys linked to the columns `project_id`, `created_by` and `updated_by`.

And the migration `m170101_010101_ticket_employee` will generate a table with the columns.

- `ticket_id`
- `employee_id`
- `created_at`

With a composite primary key of the columns `ticket_id` and `employee_id` and two foreign keys linked to the previous two columns.

### Create View Migrations

[](#create-view-migrations)

You can use the `tecnocen\migrate\CreateViewMigration` to generate SQL views migrations.

```
use tecnocen\migrate\CreateViewMigration;
use common\models\Ticket;

class m17010101_010101_ticket_details extends CreateViewMigration
{
    /**
     * @inheritdoc
     */
    public function viewName()
    {
       return 'ticket_details';
    }

    /**
     * @inheritdoc
     */
    public function viewQuery()
    {
        return Ticket::find()
            ->alias('t')
            ->innerJoinWith([
                'project' => function ($query) {
                    $query->alias('p');
                },
            ])->select([
                'ticket_id' => 't.id',
                'project_id' => 'p.id',
                'ticket_title' => 't.title',
                'ticket_description' => 't.description',
                'project_name' => 'p.name',t
            ]);
    }
}
```

Where `viewName()` returns an string and `viewQuery()` return an instance of `yii\db\Query`

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~50 days

Total

3

Last Release

3200d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d5f64412ef020f8c137ff5c7f5e4a0866271f2f9ba9584e5a24aa48467f958d?d=identicon)[Faryshta](/maintainers/Faryshta)

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

---

Top Contributors

[![Faryshta](https://avatars.githubusercontent.com/u/2029247?v=4)](https://github.com/Faryshta "Faryshta (9 commits)")[![josejesusguzman](https://avatars.githubusercontent.com/u/8755301?v=4)](https://github.com/josejesusguzman "josejesusguzman (2 commits)")[![BerkantC](https://avatars.githubusercontent.com/u/7061013?v=4)](https://github.com/BerkantC "BerkantC (1 commits)")

---

Tags

frameworkmigrationyii2advancedmigrate

### Embed Badge

![Health badge](/badges/tecnocen-yii2-migrate/health.svg)

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

###  Alternatives

[funson86/yii2-adminlte

Yii 2 Advanced Application Template with Adminlte Theme

1492.2k](/packages/funson86-yii2-adminlte)[izyue/yii2-app-advanced

Yii 2 Advanced Project Template

1281.9k](/packages/izyue-yii2-app-advanced)[beaten-sect0r/yii2-core

Yii2 Core project template

771.1k](/packages/beaten-sect0r-yii2-core)

PHPackages © 2026

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