<?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation for table `brand_lang`.
     */
    class m160928_122509_create_brand_lang_table extends Migration
    {
        
        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable('brand_lang', [
                'brand_id'    => $this->integer()
                                      ->notNull(),
                'language_id' => $this->integer()
                                      ->notNull(),
                'name'        => $this->string()
                                      ->notNull(),
                'meta_title'  => $this->string(),
                'meta_robots' => $this->string(),
                'meta_desc'   => $this->string(),
                'seo_text'    => $this->text(),
            ]);
            
            $this->createIndex('brand_lang_brand_language_key', 'brand_lang', [
                'brand_id',
                'language_id',
            ], true);
            
            $this->addForeignKey('brand_fk', 'brand_lang', 'brand_id', 'brand', 'brand_id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('language_fk', 'brand_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
        }
        
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropTable('brand_lang');
        }
    }
