<?php

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

class m160215_210504_user_statistics extends Migration
{
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') 
        {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
        }
        
        // Структура таблицы `user_statistics`
 
        $this->createTable('user_statistics', [
            'id' => Schema::TYPE_PK,
            'lesson_id' => Schema::TYPE_INTEGER . '(11)',
            'user_id' => Schema::TYPE_INTEGER . '(11) NOT NULL',
            'facebook' => Schema::TYPE_INTEGER . '(11)',
            'vkontakte' => Schema::TYPE_INTEGER . '(11)',
            'gplus' => Schema::TYPE_INTEGER . '(11)',
            'twitter' => Schema::TYPE_INTEGER . '(11)',
            'tumblr' => Schema::TYPE_INTEGER . '(11)',
        ], $tableOptions);
        
        $this->createIndex('FK_user_statistics_users', 'user_statistics', 'user_id');
        $this->createIndex('FK_user_statistics_lessons', 'user_statistics', 'lesson_id');
    }

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