<?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation for table `product_unit_lang`.
     */
    class m160929_173535_create_product_unit_lang_table extends Migration
    {
        
        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable('product_unit_lang', [
                'product_unit_id' => $this->integer()
                                          ->notNull(),
                'language_id'     => $this->integer()
                                          ->notNull(),
                'name'            => $this->string()
                                          ->notNull(),
                'short'           => $this->string(),
            ]);
            
            $this->createIndex('product_unit_lang_product_unit_language_key', 'product_unit_lang', [
                'product_unit_id',
                'language_id',
            ], true);
            
            $this->addForeignKey('product_unit_fk', 'product_unit_lang', 'product_unit_id', 'product_unit', 'product_unit_id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('language_fk', 'product_unit_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
        }
        
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropTable('product_unit_lang');
        }
    }
