<?php

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

class m160225_043622_fix_passing_table extends Migration
{
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $this->alterColumn('testings_passings', 'attempt', Schema::TYPE_INTEGER . '(3) NOT NULL DEFAULT 0');

        $this->addColumn('testings_passings', 'percent', Schema::TYPE_INTEGER . '(11) NOT NULL DEFAULT 0 AFTER points');

        $this->addColumn('testings_passings', 'passed', Schema::TYPE_INTEGER . '(1) NOT NULL DEFAULT 0 AFTER status');

        $this->dropTable('testings_mistakes');
    }

    public function safeDown()
    {
        $this->alterColumn('testings_passings', 'attempt', Schema::TYPE_INTEGER . '(3) NOT NULL');

        $this->dropColumn('testings_passings', 'percent');
        
        $this->dropColumn('testings_passings', 'passed');

        $this->createTable('testings_mistakes', [
            'id' => Schema::TYPE_PK,
            'passing_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', 
            'description' => Schema::TYPE_STRING . '(3000) NOT NULL', 
            'is_expert_agreed' => 'tinyint(1) NOT NULL', 
            'create_date' => Schema::TYPE_TIMESTAMP . ' NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 
        ]);
    }
}
