Test Failed
Push — master ( f8a509...4677ed )
by Loban
02:55
created

m170427_214256_create_activity_log   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 19
c 0
b 0
f 0
dl 0
loc 34
rs 10
1
<?php
2
3
use yii\db\Migration;
4
5
class m170427_214256_create_activity_log extends Migration
6
{
7
    private $tableOptions;
8
9
    public function init()
10
    {
11
        parent::init();
12
        if ($this->db->driverName === 'mysql') {
13
            /** @see https://stackoverflow.com/questions/766809 */
14
            $this->tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
15
        }
16
    }
17
18
    public function safeUp()
19
    {
20
        $this->createTable('{{%activity_log}}', [
21
            'id' => $this->bigPrimaryKey(),
22
            'entity_name' => $this->string(32)->notNull(),
23
            'entity_id' => $this->string(32),
24
            'created_at' => $this->integer()->notNull(),
25
            'user_id' => $this->string(32),
26
            'user_name' => $this->string(255),
27
            'action' => $this->string(32),
28
            'env' => $this->string(32),
29
            'data' => $this->text(),
30
        ], $this->tableOptions);
31
32
        $this->createIndex('activity_log-entity_name-entity_id-idx', '{{%activity_log}}', ['entity_name', 'entity_id']);
33
        $this->createIndex('activity_log-user_id', '{{%activity_log}}', 'user_id');
34
    }
35
36
    public function safeDown()
37
    {
38
        $this->dropTable('{{%activity_log}}');
39
    }
40
}
41