<?php

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

class m160127_082148_trigger_scenario extends Migration
{
    /*public function up()
    {

    }

    public function down()
    {
        echo "m160127_082148_trigger_scenario cannot be reverted.\n";

        return false;
    }*/

    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        Yii::$app->db->createCommand('ALTER TABLE `users` ENGINE = InnoDB;')->execute();
        Yii::$app->db->createCommand('ALTER TABLE `users` CHANGE `id` `id` INT(11) NOT NULL AUTO_INCREMENT;')->execute();
        $this->createTable(
            'trigger_scenario',
            [
                'id' => Schema::TYPE_PK,
                'active' => Schema::TYPE_BOOLEAN.' DEFAULT 0',
                'owner_id' => Schema::TYPE_INTEGER.' NOT NULL',
                'name' => Schema::TYPE_STRING.' NOT NULL',
                'description' => Schema::TYPE_TEXT,
                'date_create' => Schema::TYPE_DATETIME.' NOT NULL'
            ]
        );
        $this->addForeignKey(
            'fk_scenario_owner_id_users_id',
            'trigger_scenario', 'owner_id',
            'users', 'id'
        );
    }

    public function safeDown()
    {
        $this->dropForeignKey('fk_scenario_owner_id_users_id', 'trigger_scenario');
        $this->dropTable('trigger_scenario');
        Yii::$app->db->createCommand('ALTER TABLE `users` CHANGE `id` `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT;')->execute();
        Yii::$app->db->createCommand('ALTER TABLE `users` ENGINE = MyISAM;')->execute();
    }
}
