1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.yiiframework.com/ |
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
5
|
|
|
* @license http://www.yiiframework.com/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use yii\db\Migration; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Initializes i18n messages tables. |
12
|
|
|
* |
13
|
|
|
* @author Dmitry Naumenko <[email protected]> |
14
|
|
|
* @since 2.0.7 |
15
|
|
|
*/ |
16
|
|
|
class m150207_210500_i18n_init extends Migration |
17
|
|
|
{ |
18
|
|
|
public function up() |
19
|
|
|
{ |
20
|
|
|
$tableOptions = null; |
21
|
|
|
if ($this->db->driverName === 'mysql') { |
22
|
|
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
23
|
|
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$this->createTable('source_message', [ |
27
|
|
|
'id' => $this->primaryKey(), |
28
|
|
|
'category' => $this->string(), |
29
|
|
|
'message' => $this->text(), |
30
|
|
|
], $tableOptions); |
31
|
|
|
|
32
|
|
|
$this->createTable('message', [ |
33
|
|
|
'id' => $this->integer(), |
34
|
|
|
'language' => $this->string(16), |
35
|
|
|
'translation' => $this->text(), |
36
|
|
|
], $tableOptions); |
37
|
|
|
|
38
|
|
|
$this->addPrimaryKey('pk_message_id_language', 'message', ['id', 'language']); |
39
|
|
|
$this->addForeignKey('fk_message_source_message', 'message', 'id', 'source_message', 'id', 'CASCADE', 'RESTRICT'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function down() |
43
|
|
|
{ |
44
|
|
|
$this->dropForeignKey('fk_message_source_message', 'message'); |
45
|
|
|
$this->dropTable('message'); |
46
|
|
|
$this->dropTable('source_message'); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|