Completed
Push — master ( e219aa...e1fcb3 )
by Nate
06:24 queued 05:08
created

Install   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 83
ccs 0
cts 67
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 69 1
A safeDown() 0 4 1
1
<?php
2
3
namespace flipbox\domains\migrations;
4
5
use craft\db\Migration;
6
use craft\records\Element;
7
use craft\records\Field;
8
use craft\records\Site;
9
use flipbox\domains\records\Domain;
10
11
class Install extends Migration
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function safeUp()
17
    {
18
        $this->createTable(Domain::tableName(), [
19
            'fieldId' => $this->integer()->notNull(),
20
            'elementId' => $this->integer()->notNull(),
21
            'domain' => $this->string()->notNull(),
22
            'status' => $this->enum('status', ['enabled', 'pending', 'disabled'])->notNull()->defaultValue('enabled'),
23
            'sortOrder' => $this->smallInteger()->unsigned(),
24
            'siteId' => $this->integer()->notNull(),
25
            'dateCreated' => $this->dateTime()->notNull(),
26
            'dateUpdated' => $this->dateTime()->notNull(),
27
            'uid' => $this->uid(),
28
        ]);
29
30
        $this->addPrimaryKey(
31
            null,
32
            Domain::tableName(),
33
            [
34
                'fieldId',
35
                'elementId',
36
                'domain',
37
                'siteId'
38
            ]
39
        );
40
41
        $this->createIndex(
42
            null,
43
            Domain::tableName(),
44
            'domain',
45
            false
46
        );
47
48
        $this->createIndex(
49
            null,
50
            Domain::tableName(),
51
            'status',
52
            false
53
        );
54
55
        $this->addForeignKey(
56
            null,
57
            Domain::tableName(),
58
            'fieldId',
59
            Field::tableName(),
60
            'id',
61
            'CASCADE',
62
            null
63
        );
64
65
        $this->addForeignKey(
66
            null,
67
            Domain::tableName(),
68
            'elementId',
69
            Element::tableName(),
70
            'id',
71
            'CASCADE',
72
            null
73
        );
74
75
        $this->addForeignKey(
76
            null,
77
            Domain::tableName(),
78
            'siteId',
79
            Site::tableName(),
80
            'id',
81
            'CASCADE',
82
            'CASCADE'
83
        );
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89
    public function safeDown()
90
    {
91
        $this->dropTableIfExists(Domain::tableName());
92
    }
93
}
94