<?php

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

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

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