Completed
Push — master ( f45cc5...2edd5b )
by Igor
05:32
created

m161026_103037_create_news_files::safeUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 2
eloc 13
nc 2
nop 0
1
<?php
2
3
use yii\db\Schema;
4
5
class m161026_103037_create_news_files extends \yii\db\Migration
6
{
7
    public function safeUp()
8
    {
9
        $tableOptions = null;
10
        if ($this->db->driverName === 'mysql') {
11
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
12
        }
13
14
        $this->createTable('{{%news_files}}', [
15
            'id' => Schema::TYPE_PK,
16
            'news_id' => Schema::TYPE_INTEGER . " NOT NULL DEFAULT 0",
17
            'file_id' => Schema::TYPE_INTEGER . " NOT NULL DEFAULT 0",
18
            'type' => Schema::TYPE_INTEGER . " NOT NULL DEFAULT 0",
19
            'position' => Schema::TYPE_INTEGER . " NOT NULL DEFAULT 0",
20
        ], $tableOptions);
21
22
        $this->createIndex('link', '{{%news_files}}', 'news_id, file_id');
23
        $this->createIndex('type_news', '{{%news_files}}', 'type, news_id');
24
    }
25
26
    public function safeDown()
27
    {
28
        $this->dropTable('{{%news_files}}');
29
    }
30
}
31