<?php

use yii\db\Schema;
use yii\db\Migration;

class m160209_233922_create_table_courses_lang extends Migration
{
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') 
        {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
        }
        
        // Структура таблицы `courses_lang`
 
        $this->createTable('courses_lang', [
            'id' => Schema::TYPE_PK,
            'lang_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'course_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'title' => Schema::TYPE_STRING . '(150) NOT NULL',
            'description' => Schema::TYPE_TEXT . ' NOT NULL',
            'description_for_course' => Schema::TYPE_TEXT . ' NOT NULL',
        ], $tableOptions);
        
        $this->createIndex('FK_courses_lang_languages', 'courses_lang', 'lang_id');
        $this->createIndex('FK_courses_lang_courses', 'courses_lang', 'course_id');
    }

    public function safeDown()
    {
        $this->dropTable('courses_lang');
    }
}
