m170613_075310_create_slider_table.php 1.25 KB
<?php
    
    use yii\db\Migration;
    
    /**
     * Handles the creation of table `slider`.
     */
    class m170613_075310_create_slider_table extends Migration
    {
        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable(
                'slider',
                [
                    'id'       => $this->primaryKey(),
                    'image_id' => $this->integer()
                                       ->notNull(),
                    'link'     => $this->string(),
                    'status'   => $this->boolean()
                                       ->defaultValue(true),
                    'sort'     => $this->integer()
                                       ->defaultValue(0),
                ]
            );
            $this->addForeignKey(
                'slider_image_id_fkey',
                'slider',
                'image_id',
                'ImageManager',
                'id',
                'CASCADE',
                'CASCADE'
            );
        }
        
        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropForeignKey('slider_image_id_fkey', 'slider');
            $this->dropTable('slider');
        }
    }