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

m190809_120000_article   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 23
c 1
b 0
f 1
dl 0
loc 44
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 31 1
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