<?php

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

class m160218_184352_update_passings_table extends Migration
{
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $this->renameColumn('testings_passings', 'percent_rights', 'points');
        $this->renameColumn('testings_passings', 'pass_date', 'start_date');
        $this->renameColumn('testings_passings', 'is_passed', 'status');

        $this->dropColumn('testings_passings', 'create_date');
        $this->dropColumn('testings_passings', 'pass_date_start');

        $this->alterColumn('testings_passings', 'status', Schema::TYPE_INTEGER . '(4) NOT NULL DEFAULT 0');
        $this->alterColumn('testings_passings', 'points', Schema::TYPE_INTEGER . '(11) NOT NULL DEFAULT 0');
    }

    public function safeDown()
    {
        $this->renameColumn('testings_passings', 'points', 'percent_rights');
        $this->renameColumn('testings_passings', 'start_date', 'pass_date');
        $this->renameColumn('testings_passings', 'status', 'is_passed');

        $this->addColumn(
            'testings_passings', 
            'create_date', 
            Schema::TYPE_TIMESTAMP . ' NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
        );
        $this->addColumn('testings_passings', 'pass_date_start', Schema::TYPE_STRING . '(22) NOT NULL');

        $this->alterColumn('testings_passings', 'is_passed', 'tinyint(1) DEFAULT NULL');
        $this->alterColumn('testings_passings', 'percent_rights', Schema::TYPE_INTEGER . '(11) NOT NULL');
    }
}
