Passed
Push — scrutinizer-migrate-to-new-eng... ( 58afd6 )
by Alexander
18:11
created

m150207_210500_i18n_init   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 35
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 24 2
A down() 0 5 1
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