m160225_143331_comment_test.php 1.17 KB
<?php

use yii\db\Migration;

class m160225_143331_comment_test extends Migration
{
    public function up()
    {
        $this->createTable('{{%comment}}', [
            'comment_id' => $this->primaryKey(),
            'entity' => $this->string()->notNull(),
            'text' => $this->text()->notNull(),
            'user_id' => $this->integer(),
            'user_name' => $this->string(),
            'user_email' => $this->string(),
            'comment_pid' => $this->integer(),
            'status' => $this->integer(),
            'date_add' => $this->timestamp()->notNull()->defaultExpression('NOW()'),
            'date_update' => $this->timestamp()->notNull()->defaultExpression('NOW()'),
            'date_delete' => $this->timestamp(),
        ]);

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

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

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}