<?php

use yii\db\Migration;

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

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

        $this->addForeignKey(
            'fk-product-company_id',
            'product',
            'company_id',
            'company',
            'id',
            'CASCADE'
        );
    }

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

        // drops index for column `author_id`
        $this->dropIndex(
            'idx-product-company_id',
            'product'
        );

        $this->dropTable('{{%product}}');
    }
}
