m160208_095412_portfolio.php 1.57 KB
<?php

use yii\db\Migration;

class m160208_095412_portfolio extends Migration
{
    public function up()
    {
        $tableOptions = null;

        $this->createTable('{{%portfolio}}', [
            'portfolio_id' => $this->primaryKey(),
            'user_id' =>  $this->integer()->notNull(),
            'name' => $this->string(255)->notNull(),
            'link' => $this->string(255),
            'date_add' => $this->timestamp()->notNull(),
            'user_add_id' => $this->integer(),
            'view_count' => $this->integer()->defaultValue(0),
            'city' =>  $this->string(255),
            'street' =>  $this->string(255),
            'house' =>  $this->string(255),
            'description' =>  $this->text(),
            'cover' =>  $this->text(),
            'gallery_id' =>  $this->integer(),
        ], $tableOptions);
        $this->createTable (
            '{{%portfolio_specialization}}', [
                'portfolio_specialization_id' => $this->primaryKey (), 'portfolio_id' => $this->integer (), 'specialization_id' => $this->integer (),
            ]
        );
        $this->addForeignKey ('portfolio_specialization_index', '{{%portfolio_specialization}}', 'specialization_id', '{{%specialization}}', 'specialization_id', 'CASCADE', 'CASCADE');
        $this->addForeignKey ('specialization_portfolio_index', '{{%portfolio_specialization}}', 'portfolio_id', '{{%portfolio}}', 'portfolio_id', 'CASCADE', 'CASCADE');
    }

    public function down()
    {

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