Passed
Branch master (b01856)
by Alexander
02:16
created

m190809_120000_article::safeUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use yii\db\Migration;
4
5
class m190809_120000_article extends Migration
6
{
7
    /**
8
     * @return bool|void
9
     */
10
    public function safeUp()
11
    {
12
        $this->createTable('{{%articles}}', [
13
            'id' => $this->primaryKey(),
14
            'title' => $this->string()->notNull(),
15
            'content' => $this->text(),
16
            'category_id' => $this->integer()->notNull(),
17
        ]);
18
19
        $this->createTable('{{%article_categories}}', [
20
            'id' => $this->primaryKey(),
21
            'name' => $this->string()->notNull(),
22
        ]);
23
24
        $this->insert('{{%article_categories}}', [
25
            'id' => 1,
26
            'name' => 'Category1'
27
        ]);
28
        $this->insert('{{%article_categories}}', [
29
            'id' => 2,
30
            'name' => 'Category2'
31
        ]);
32
        $this->insert('{{%articles}}', [
33
            'category_id' => 1,
34
            'title' => 'Article1'
35
        ]);
36
        $this->insert('{{%articles}}', [
37
            'category_id' => 1,
38
            'title' => 'Article2'
39
        ]);
40
    }
41
42
    /**
43
     * @return bool|void
44
     */
45
    public function safeDown()
46
    {
47
        $this->dropTable('{{%articles}}');
48
        $this->dropTable('{{%article_categories}}');
49
    }
50
}
51