<?php

use yii\db\Migration;

/**
 * Handles the creation of table `event_tag_lang`.
 */
class m180507_123737_create_event_tag_lang_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('event_tag_lang', [
            'id' => $this->primaryKey(),
            'event_tag_id' => $this->integer()
                                  ->notNull(),
            'language_id' => $this->integer()
                                  ->notNull(),
            'alias_id'    => $this->integer(),
            'title'       => $this->string(255),
        ]);
    
        $this->createIndex(
            'event_tag_lang_uk',
            'event_tag_lang',
            [
                'event_tag_id',
                'language_id',
            ],
            true
        );
    
        $this->createIndex('event_tag_lang_auk', 'event_tag_lang', 'alias_id', true);
    
        $this->addForeignKey(
            'event_tag_lang_fk',
            'event_tag_lang',
            'language_id',
            'language',
            'id',
            'RESTRICT',
            'CASCADE'
        );
    
        $this->addForeignKey(
            'event_tag_fk',
            'event_tag_lang',
            'event_tag_id',
            'event_tag',
            'id',
            'CASCADE',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey('event_tag_fk', 'event_tag_lang');
        $this->dropForeignKey('event_tag_lang_fk', 'event_tag_lang');
        $this->dropIndex('event_tag_lang_uk', 'event_tag_lang');
        $this->dropTable('event_tag_lang');
    }
}
