1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace bedezign\yii2\audit\migrations; |
4
|
|
|
|
5
|
|
|
use bedezign\yii2\audit\components\Migration; |
6
|
|
|
use yii\db\Schema; |
7
|
|
|
|
8
|
|
|
class m150626_000004_create_audit_trail extends Migration |
9
|
|
|
{ |
10
|
|
|
const TABLE = '{{%audit_trail}}'; |
11
|
|
|
|
12
|
|
|
public function up() |
13
|
|
|
{ |
14
|
|
|
$this->createTable(self::TABLE, [ |
15
|
|
|
'id' => Schema::TYPE_PK, |
16
|
|
|
'entry_id' => Schema::TYPE_INTEGER, |
17
|
|
|
'user_id' => Schema::TYPE_INTEGER . ' NULL', |
18
|
|
|
'action' => Schema::TYPE_STRING . ' NOT NULL', |
19
|
|
|
'model' => Schema::TYPE_STRING . ' NOT NULL', |
20
|
|
|
'model_id' => Schema::TYPE_STRING . ' NOT NULL', |
21
|
|
|
'field' => Schema::TYPE_STRING, |
22
|
|
|
'old_value' => Schema::TYPE_TEXT, |
23
|
|
|
'new_value' => Schema::TYPE_TEXT, |
24
|
|
|
'created' => Schema::TYPE_DATETIME . ' NOT NULL', |
25
|
|
|
], ($this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB' : null)); |
26
|
|
|
|
27
|
|
|
if ($this->db->driverName != 'sqlite') { |
28
|
|
|
$this->addForeignKey('fk_audit_trail_entry_id', self::TABLE, ['entry_id'], '{{%audit_entry}}', 'id'); |
29
|
|
|
} |
30
|
|
|
$this->createIndex('idx_audit_user_id', self::TABLE, 'user_id'); |
31
|
|
|
$this->createIndex('idx_audit_trail_field', self::TABLE, ['model', 'model_id', 'field']); |
32
|
|
|
$this->createIndex('idx_audit_trail_action', self::TABLE, 'action'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function down() |
36
|
|
|
{ |
37
|
|
|
if ($this->db->driverName != 'sqlite') { |
38
|
|
|
$this->dropForeignKey('fk_audit_trail_entry_id', self::TABLE); |
39
|
|
|
} |
40
|
|
|
$this->dropTable(self::TABLE); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|