<?php

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

class m160201_134526_trigger_params_table extends Migration
{
//    public function up()
//    {
//
//    }
//
//    public function down()
//    {
//        echo "m160201_134526_trigger_params_table cannot be reverted.\n";
//
//        return false;
//    }


    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $this->createTable(
            'trigger_param',
            [
                'id' => Schema::TYPE_PK,
                'condition_id' => Schema::TYPE_INTEGER.' NOT NULL',
                'key' => Schema::TYPE_TEXT,
                'value' => Schema::TYPE_TEXT
            ]
        );
        $this->addColumn(
            'trigger_condition',
            'condition_id',
            Schema::TYPE_INTEGER.' NOT NULL'
        );
        $this->addForeignKey(
            'fk_trigger_param_condition',
            'trigger_param', 'condition_id',
            'trigger_condition', 'id'
        );
    }

    public function safeDown()
    {
        $this->dropForeignKey(
            'fk_trigger_param_condition',
            'trigger_param'
        );
        $this->dropColumn(
            'trigger_condition',
            'condition_id'
        );
        $this->dropTable('trigger_param');
    }
}
