m160304_081817_rating_table.php 781 Bytes
<?php

use yii\db\Migration;

class m160304_081817_rating_table extends Migration
{
    public function up()
    {
        $this->createTable('{{%rating}}', [
            'rating_id' => $this->primaryKey(),
            'date_add' => $this->timestamp()->notNull()->defaultExpression('NOW()'),
            'date_update' => $this->timestamp()->notNull()->defaultExpression('NOW()'),
            'user_id' => $this->integer(),
            'entity' => $this->string(),
            'value' => $this->integer(),
        ]);

        $this->addForeignKey('rating_user', '{{%rating}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'CASCADE');
    }

    public function down()
    {
        $this->dropForeignKey('rating_user', '{{%rating}}');
        $this->dropTable('{{%rating}}');
    }

}