1 | <?php |
||
22 | class m141106_185632_log_init extends Migration |
||
23 | { |
||
24 | /** |
||
25 | * @var DbTarget[] Targets to create log table for |
||
26 | */ |
||
27 | private $dbTargets = []; |
||
28 | |||
29 | /** |
||
30 | * @throws InvalidConfigException |
||
31 | * @return DbTarget[] |
||
32 | */ |
||
33 | 6 | protected function getDbTargets() |
|
59 | } |
||
60 | |||
61 | 6 | public function up() |
|
62 | { |
||
63 | 6 | foreach ($this->getDbTargets() as $target) { |
|
64 | 6 | $this->db = $target->db; |
|
65 | |||
66 | 6 | $tableOptions = null; |
|
67 | 6 | if ($this->db->driverName === 'mysql') { |
|
68 | // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
||
69 | 6 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
|
70 | } |
||
71 | |||
72 | 6 | $this->createTable($target->logTable, [ |
|
73 | 6 | 'id' => $this->bigPrimaryKey(), |
|
74 | 6 | 'level' => $this->integer(), |
|
75 | 6 | 'category' => $this->string(), |
|
76 | 6 | 'log_time' => $this->double(), |
|
77 | 6 | 'prefix' => $this->text(), |
|
78 | 6 | 'message' => $this->text(), |
|
79 | 6 | ], $tableOptions); |
|
80 | |||
81 | 6 | $this->createIndex('idx_log_level', $target->logTable, 'level'); |
|
82 | 6 | $this->createIndex('idx_log_category', $target->logTable, 'category'); |
|
83 | } |
||
84 | 6 | } |
|
85 | |||
86 | 6 | public function down() |
|
92 | } |
||
93 | 6 | } |
|
94 | } |
||
95 |