<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%product_category}}`.
 */
class m240212_213157_create_product_category_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%product_category}}', [
            'id' => $this->primaryKey(),
            'title' => $this->string('255')->notNull(),
            'parent_id' => $this->integer(11)->defaultValue(0),
            'company_id' => $this->integer(11)->notNull(),
            'status' => $this->integer(1)->defaultValue(1),
        ]);

        $this->createIndex(
            'idx-product_category-company_id',
            'product_category',
            'company_id'
        );

        // add foreign key for table `user`
        $this->addForeignKey(
            'fk-product_category-company_id',
            'product_category',
            'company_id',
            'company',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey(
            'fk-product_category-company_id',
            'product_category'
        );

        // drops index for column `author_id`
        $this->dropIndex(
            'idx-product_category-company_id',
            'product_category'
        );
        $this->dropTable('{{%product_category}}');
    }
}
