m160304_054017_realtion.php 1.16 KB
<?php

use yii\db\Migration;

class m160304_054017_realtion extends Migration
{
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // Only for MySQL
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

            // @todo https://habrahabr.ru/post/138947/
        } elseif ($this->db->driverName === 'pgsql') {
            // Only for PostgreSQL
            // @todo use intarray field for tax_options
        }
        $this->createTable('{{%relation}}', [
            'alias' => $this->string(50)->notNull(),
            'entity1_id' => $this->integer()->notNull(),
            'entity2_id' => $this->integer()->notNull(),
        ], $tableOptions);
        $this->addPrimaryKey('relation_ukey', 'relation', ['alias', 'entity1_id', 'entity2_id']);
    }

    public function down()
    {
        $this->dropTable('{{%relation}}');

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}