Completed
Push — master ( e41cc1...feed29 )
by Andrey
08:18
created

m180509_092225_create_articles_table   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 2
lcom 2
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 46 1
A safeDown() 0 24 1
1
<?php
2
3
use yii\db\Migration;
4
5
/**
6
 * Handles the creation of table `articles`.
7
 */
8
class m180509_092225_create_articles_table extends Migration
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    public function safeUp()
14
    {
15
        $this->createTable('articles',
16
            [
17
                'id' => $this->primaryKey(),
18
                'pageId' => $this->integer(),
19
                'active' => $this->tinyInteger()->notNull()->defaultValue(0),
20
                'icon' => $this->string(128),
21
                'title' => $this->string(128),
22
                'description' => $this->text(),
23
                'content' => $this->text(),
24
                'metaKeys' => $this->string(128),
25
                'metaDescription' => $this->string(),
26
                'alias' => $this->string(128),
27
                'created_at' => $this->dateTime(),
28
                'updated_at' => $this->dateTime(),
29
            ]
30
        );
31
32
        $this->createIndex(
33
            'idx-articles-pageId',
34
            'articles',
35
            'pageId'
36
        );
37
38
        $this->addForeignKey(
39
            'fk-articles-pageId',
40
            'articles',
41
            'pageId',
42
            'pages',
43
            'id',
44
            'SET NULL'
45
        );
46
47
        $this->createIndex(
48
            'idx-articles-active',
49
            'articles',
50
            'active'
51
        );
52
53
        $this->createIndex(
54
            'idx-articles-alias',
55
            'articles',
56
            'alias'
57
        );
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function safeDown()
64
    {
65
        $this->dropIndex(
66
            'idx-articles-alias',
67
            'articles'
68
        );
69
70
        $this->dropIndex(
71
            'idx-articles-active',
72
            'articles'
73
        );
74
75
        $this->dropForeignKey(
76
            'fk-articles-pageId',
77
            'articles'
78
        );
79
80
        $this->dropIndex(
81
            'idx-articles-pageId',
82
            'articles'
83
        );
84
85
        $this->dropTable('articles');
86
    }
87
}
88