Total Complexity | 4 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
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 | } |
||
41 |