Passed
Push — master ( dd4450...9a9614 )
by Andrey
05:55
created

m180509_092225_create_articles_table   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

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

2 Methods

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