<?php

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

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

    }

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

        return false;
    }*/


    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $this->createTable(
            'trigger_trigger',
            [
                'id' => Schema::TYPE_PK,
                'active' => Schema::TYPE_BOOLEAN.' DEFAULT 0',
                'name' => Schema::TYPE_STRING.' NOT NULL',
                'description' => Schema::TYPE_TEXT.' DEFAULT NULL',
                'owner_id' => Schema::TYPE_INTEGER.' NOT NULL',
                'date_create' => Schema::TYPE_DATETIME,
                'timeout' => Schema::TYPE_INTEGER.' NOT NULL DEFAULT 0',
                'message_template_id' => Schema::TYPE_INTEGER.' DEFAULT 0'
            ]
        );
        $this->addForeignKey(
            'fk_trigger_owner_id_users_id',
            'trigger_trigger', 'owner_id',
            'users', 'id'
        );
    }

    public function safeDown()
    {
        $this->dropForeignKey('fk_trigger_owner_id_users_id', 'trigger_trigger');
        $this->dropTable('trigger_trigger');
    }
}
