<?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation for table `project_lang`.
     */
    class m160930_082350_create_project_lang_table extends Migration
    {
        
        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable('project_lang', [
                'project_id'  => $this->integer()
                                      ->notNull(),
                'language_id' => $this->integer()
                                      ->notNull(),
                'title'       => $this->string()
                                      ->notNull(),
                'description' => $this->text(),
            ]);
            $this->createIndex('project_lang_project_language_key', 'project_lang', [
                'project_id',
                'language_id',
            ], true);
            
            $this->addForeignKey('project_fk', 'project_lang', 'project_id', 'project', 'project_id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('language_fk', 'project_lang', 'language_id', 'language', 'language_id', 'RESTRICT', 'CASCADE');
        }
        
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropTable('project_lang');
        }
    }
