<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%addresses}}`.
 */
class m240110_153348_create_addresses_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%addresses}}', [
            'id' => $this->primaryKey(),
            'address' => $this->string(255)->notNull(),
            'company_id' => $this->integer(11)->notNull(),
            'name' => $this->string(255),
        ]);

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

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

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

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

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