m010101_100001_init_comment::up()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 18
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 24
rs 9.6666
1
<?php
2
3
use yii\db\Migration;
4
5
/**
6
 * Class m010101_100001_init_comment
7
 */
8
class m010101_100001_init_comment extends Migration
9
{
10
    /**
11
     * Create table `Comment`
12
     */
13
    public function up()
14
    {
15
        $tableOptions = null;
16
17
        if ('mysql' === $this->db->driverName) {
18
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
19
        }
20
21
        $this->createTable('{{%Comment}}', [
22
            'id' => $this->primaryKey(),
23
            'entity' => $this->char(10)->notNull(),
24
            'entityId' => $this->integer()->notNull(),
25
            'content' => $this->text()->notNull(),
26
            'parentId' => $this->integer()->null(),
27
            'level' => $this->smallInteger()->notNull()->defaultValue(1),
28
            'createdBy' => $this->integer()->notNull(),
29
            'updatedBy' => $this->integer()->notNull(),
30
            'status' => $this->smallInteger()->notNull()->defaultValue(1),
31
            'createdAt' => $this->integer()->notNull(),
32
            'updatedAt' => $this->integer()->notNull(),
33
        ], $tableOptions);
34
35
        $this->createIndex('idx-Comment-entity', '{{%Comment}}', 'entity');
36
        $this->createIndex('idx-Comment-status', '{{%Comment}}', 'status');
37
    }
38
39
    /**
40
     * Drop table `Comment`
41
     */
42
    public function down()
43
    {
44
        $this->dropTable('{{%Comment}}');
45
    }
46
}
47