<?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation of table `page_category_lang`.
     */
    class m170718_134355_create_page_category_lang_table extends Migration
    {
        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable(
                'page_category_lang',
                [
                    'title'            => $this->string(),
                    'language_id'      => $this->integer(),
                    'page_category_id' => $this->integer(),
                ]
            );
            
            $this->addForeignKey(
                'lang_fk',
                'page_category_lang',
                'language_id',
                'language',
                'id',
                'CASCADE',
                'CASCADE'
            );
            
            $this->addForeignKey(
                'category_fk',
                'page_category_lang',
                'page_category_id',
                'page_category',
                'id',
                'CASCADE',
                'CASCADE'
            );
            
            $this->createIndex(
                'pcat_lang_uk',
                'page_category_lang',
                [
                    'language_id',
                    'page_category_id',
                ],
                true
            );
        }
        
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropIndex(
                'pcat_lang_uk',
                'page_category_lang'
            );
            
            $this->dropForeignKey(
                'category_fk',
                'page_category_lang'
            );
            
            $this->dropForeignKey(
                'lang_fk',
                'page_category_lang'
            );
            
            $this->dropTable('page_category_lang');
        }
    }
