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_000003_create_audit_error extends Migration |
9
|
|
|
{ |
10
|
|
|
const TABLE = '{{%audit_error}}'; |
11
|
|
|
|
12
|
|
|
public function up() |
13
|
|
|
{ |
14
|
|
|
$driver = $this->db->driverName; |
15
|
|
|
$this->createTable(self::TABLE, [ |
16
|
|
|
'id' => Schema::TYPE_PK, |
17
|
|
|
'entry_id' => Schema::TYPE_INTEGER . ' NOT NULL', |
18
|
|
|
'created' => Schema::TYPE_DATETIME . ' NOT NULL', |
19
|
|
|
'message' => Schema::TYPE_TEXT . ' NOT NULL', |
20
|
|
|
'code' => Schema::TYPE_INTEGER . " DEFAULT '0'", |
21
|
|
|
'file' => Schema::TYPE_STRING . '(512)', |
22
|
|
|
'line' => Schema::TYPE_INTEGER , |
23
|
|
|
'trace' => Schema::TYPE_BINARY, |
24
|
|
|
'hash' => Schema::TYPE_STRING . '(32)', |
25
|
|
|
'emailed' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0'", |
26
|
|
|
], ($driver === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB' : null)); |
27
|
|
|
|
28
|
|
|
if ($driver != 'sqlite') { |
29
|
|
|
$this->addForeignKey('fk_audit_error_entry_id', self::TABLE, ['entry_id'], '{{%audit_entry}}', 'id'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// Issue #122: Specified key was too long; max key length is 767 bytes - http://stackoverflow.com/q/1814532/50158 |
33
|
|
|
$this->createIndex('idx_file', self::TABLE, ['file' . ($driver === 'mysql' ? '(180)' : '')]); |
34
|
|
|
$this->createIndex('idx_emailed', self::TABLE, ['emailed']); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function down() |
38
|
|
|
{ |
39
|
|
|
if ($this->db->driverName != 'sqlite') { |
40
|
|
|
$this->dropForeignKey('fk_audit_error_entry_id', self::TABLE); |
41
|
|
|
} |
42
|
|
|
$this->dropTable(self::TABLE); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|