m180123_145850_create_object_table.php 1.27 KB
<?php

use yii\db\Migration;

/**
 * Handles the creation of table `object`.
 * Has foreign keys to the tables:
 *
 * - `slider`
 */
class m180123_145850_create_object_table extends Migration
{
    /**
     * @inheritdoc
     */
    public function up()
    {
        $this->createTable('object', [
            'id' => $this->primaryKey(),
            'slider_id' => $this->integer()->notNull(),
            'status' => $this->boolean(),
            'sort' => $this->integer(),
        ]);

        // creates index for column `slider_id`
        $this->createIndex(
            'idx-object-slider_id',
            'object',
            'slider_id'
        );

        // add foreign key for table `slider`
        $this->addForeignKey(
            'fk-object-slider_id',
            'object',
            'slider_id',
            'slider',
            'id',
            'CASCADE'
        );
    }

    /**
     * @inheritdoc
     */
    public function down()
    {
        // drops foreign key for table `slider`
        $this->dropForeignKey(
            'fk-object-slider_id',
            'object'
        );

        // drops index for column `slider_id`
        $this->dropIndex(
            'idx-object-slider_id',
            'object'
        );

        $this->dropTable('object');
    }
}