m160411_143038_create_portfolio_gallery.php 1.77 KB
<?php

    use yii\db\Migration;

    /**
     * Handles the creation for table `portfolio_gallery`.
     */
    class m160411_143038_create_portfolio_gallery extends Migration
    {

        /**
         * @inheritdoc
         */
        public function up()
        {
            $this->createTable('portfolio_gallery', [
                'portfolio_gallery_id' => $this->primaryKey(),
                'gallery_id'           => $this->integer()
                                               ->notNull(),
                'portfolio_id'         => $this->integer()
                                               ->notNull(),
                'user_id' => $this->integer()
                                  ->notNull(),
                'caption'              => $this->string(),
                'visible'              => $this->smallInteger()
                                               ->defaultValue(1),
            ]);
            $this->addForeignKey('portfolio_gallery_gallery', '{{%portfolio_gallery}}', 'gallery_id', '{{%gallery}}', 'gallery_id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('portfolio_gallery_portfolio', '{{%portfolio_gallery}}', 'portfolio_id', '{{%portfolio}}', 'portfolio_id', 'CASCADE', 'CASCADE');
            $this->addForeignKey('portfolio_gallery_user', '{{%portfolio_gallery}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'CASCADE');
        }

        /**
         * @inheritdoc
         */
        public function down()
        {
            $this->dropForeignKey('portfolio_gallery_user', '{{%portfolio_gallery}}');
            $this->dropForeignKey('portfolio_gallery_gallery', '{{%portfolio_gallery}}');
            $this->dropForeignKey('portfolio_gallery_portfolio', '{{%portfolio_gallery}}');
            $this->dropTable('portfolio_gallery');
        }
    }