<?php

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

class m160308_105319_create_table_likes_course 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('likes_course', [
            'id' => Schema::TYPE_PK,
            'estimate' => Schema::TYPE_INTEGER . '(11) NOT NULL',
            'user_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'course_id' => Schema::TYPE_INTEGER . '(11) NOT NULL',
        ], $tableOptions);
        
        $this->createIndex('FK_likes_course_users', 'likes_course', 'user_id');
        $this->createIndex('FK_likes_course_courses', 'likes_course', 'course_id');
    }

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