<?php

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

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

    }

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

        return false;
    }*/

    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $this->createTable(
            'trigger_connection',
            [
                'id' => Schema::TYPE_PK,
                'scenario_id' => Schema::TYPE_INTEGER.' NOT NULL',
                'trigger_id' => Schema::TYPE_INTEGER.' NOT NULL'
            ]
        );
        $this->addForeignKey(
            'fk_connection_scenario_id_scenario_id',
            'trigger_connection', 'scenario_id',
            'trigger_scenario', 'id'
        );
        $this->addForeignKey(
            'fk_connection_trigger_id_trigger_id',
            'trigger_connection', 'trigger_id',
            'trigger_trigger', 'id'
        );
    }

    public function safeDown()
    {
        $this->dropForeignKey(
            'fk_connection_trigger_id_trigger_id',
            'trigger_connection'
        );
        $this->dropForeignKey(
            'fk_connection_scenario_id_scenario_id',
            'trigger_connection'
        );
        $this->dropTable('trigger_connection');
    }
}
