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
|
|
|
* |
14
|
|
|
* |
15
|
|
|
* @author Dmitry Naumenko <[email protected]> |
16
|
|
|
* @since 2.0.7 |
17
|
|
|
*/ |
18
|
|
|
class m150207_210500_i18n_init extends Migration |
19
|
|
|
{ |
20
|
|
|
public function up() |
21
|
|
|
{ |
22
|
|
|
$tableOptions = null; |
23
|
|
|
if ($this->db->driverName === 'mysql') { |
24
|
|
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
25
|
|
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$this->createTable('{{%source_message}}', [ |
29
|
|
|
'id' => $this->primaryKey(), |
30
|
|
|
'category' => $this->string(), |
31
|
|
|
'message' => $this->text(), |
32
|
|
|
], $tableOptions); |
33
|
|
|
|
34
|
|
|
$this->createTable('{{%message}}', [ |
35
|
|
|
'id' => $this->integer()->notNull(), |
36
|
|
|
'language' => $this->string(16)->notNull(), |
37
|
|
|
'translation' => $this->text(), |
38
|
|
|
], $tableOptions); |
39
|
|
|
|
40
|
|
|
$this->addPrimaryKey('pk_message_id_language', '{{%message}}', ['id', 'language']); |
41
|
|
|
$this->addForeignKey('fk_message_source_message', '{{%message}}', 'id', '{{%source_message}}', 'id', 'CASCADE', 'RESTRICT'); |
42
|
|
|
$this->createIndex('idx_source_message_category', '{{%source_message}}', 'category'); |
43
|
|
|
$this->createIndex('idx_message_language', '{{%message}}', 'language'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function down() |
47
|
|
|
{ |
48
|
|
|
$this->dropForeignKey('fk_message_source_message', '{{%message}}'); |
49
|
|
|
$this->dropTable('{{%message}}'); |
50
|
|
|
$this->dropTable('{{%source_message}}'); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|