<?php

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

class m160218_131414_clear_testings extends Migration
{
    public function safeUp()
    {
        $this->dropTable('testings_users');
        $this->dropTable('testings_users_groups');
        $this->dropTable('testings_users_groups_assign');
        $this->dropTable('testings_users_history');
    }

    public function safeDown()
    {
        // Структура таблицы `testings_users`

        $this->createTable('testings_users', [
            'id' => Schema::TYPE_PK,
            'sex' => 'tinyint(1) NOT NULL', 
            'first_name' => Schema::TYPE_STRING . '(50) NOT NULL', 
            'patronymic' => Schema::TYPE_STRING . '(50) DEFAULT NULL', 
            'last_name' => Schema::TYPE_STRING . '(50) NOT NULL', 
            'company_name' => Schema::TYPE_STRING . '(250) NOT NULL', 
            'city' => Schema::TYPE_STRING . '(100) DEFAULT NULL', 
            'login' => Schema::TYPE_STRING . '(30) NOT NULL', 
            'password' => Schema::TYPE_STRING . '(30) NOT NULL', 
            'email' => Schema::TYPE_STRING . '(150) NOT NULL', 
            'manager_id' => Schema::TYPE_INTEGER . '(11) unsigned NOT NULL', 
            'tki' => Schema::TYPE_STRING . '(150) DEFAULT NULL', 
            'region' => Schema::TYPE_STRING . '(100) DEFAULT NULL', 
            'is_auth' => "tinyint(1) DEFAULT '0'", 
            'create_date' => Schema::TYPE_TIMESTAMP . ' NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
        ]);

        // Структура таблицы `testings_users_groups`

        $this->createTable('testings_users_groups', [
            'id' => Schema::TYPE_PK,
            'session_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'name' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 
            'created' => Schema::TYPE_TIMESTAMP . ' NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
        ]);

        // Структура таблицы `testings_users_groups_assign`

        $this->createTable('testings_users_groups_assign', [
            'user_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'group_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'session_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
        ]);

        // Структура таблицы `testings_users_history`

        $this->createTable('testings_users_history', [
            'id' => Schema::TYPE_PK,
            'session_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'user_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'email' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 
            'sended' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'file' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 
            'unisender_email' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 
            'unisender_status' => Schema::TYPE_STRING . '(20) DEFAULT NULL', 
            'notified' => Schema::TYPE_INTEGER . '(1) NOT NULL', 
            'created' => Schema::TYPE_TIMESTAMP . ' NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
        ]);

        $this->createIndex('testings_users2users', 'testings_users', 'manager_id');
    }
}
