<?php

use yii\db\Migration;

class m170303_145834_add_category_to_purpose_table extends Migration
{
    public function up()
    {
        $this->createTable('category_to_purpose', [
            'category_id' => $this->integer()->notNull(),
            'purpose_id' => $this->integer()->notNull(),
            'image' => $this->string()
        ]);
        $this->addForeignKey('category_to_purpose_to_category', 'category_to_purpose', 'category_id', 'category', 'category_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey('category_to_purpose_to_purpose', 'category_to_purpose', 'purpose_id', 'tax_option', 'tax_option_id', 'CASCADE', 'CASCADE');
    }

    public function down()
    {
        $this->dropForeignKey('category_to_purpose_to_category', 'category_to_purpose');
        $this->dropForeignKey('category_to_purpose_to_purpose', 'category_to_purpose');
        $this->dropTable('category_to_purpose');
    }
}
