Install   A
last analyzed

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