<?php

use yii\db\Migration;

class m160907_101042_events_to_products extends Migration
{
    public function up()
    {
        $this->createTable('events_to_products', [
            'events_to_products_id' => $this->primaryKey(),
            'event_id' => $this->integer()->notNull(),
            'product_id' => $this->integer()->notNull(),
        ]);
        $this->addForeignKey('events_to_products_to_event_fk', 'events_to_products', 'event_id', 'event', 'event_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey('events_to_products_to_product_fk', 'events_to_products', 'product_id', 'product', 'product_id', 'CASCADE', 'CASCADE');
    }

    public function down()
    {
        $this->dropForeignKey('events_to_products_to_event_fk', 'events_to_products');
        $this->dropForeignKey('events_to_products_to_product_fk', 'events_to_products');
        $this->dropTable('events_to_products');
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
