Completed
Push — master ( 874936...5f953b )
by Nate
10:31 queued 07:47
created

ObjectAssociation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 103
ccs 35
cts 56
cp 0.625
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 8 1
A safeDown() 0 5 1
A createTables() 0 13 1
A createIndexes() 0 19 1
A addForeignKeys() 0 30 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\hubspot\migrations;
10
11
use craft\db\Migration;
12
use craft\records\Element as ElementRecord;
13
use craft\records\Field as FieldRecord;
14
use craft\records\Site as SiteRecord;
15
use flipbox\hubspot\records\ObjectAssociation as ObjectAssociationRecord;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class ObjectAssociation extends Migration
22
{
23
    /**
24
     * @inheritdoc
25
     */
26 3
    public function safeUp()
27
    {
28 3
        $this->createTables();
29 3
        $this->createIndexes();
30 3
        $this->addForeignKeys();
31
32
        return true;
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function safeDown()
39
    {
40
        $this->dropTableIfExists(ObjectAssociationRecord::tableName());
41
        return true;
42
    }
43
44
    /**
45
     * Creates the tables.
46
     *
47
     * @return void
48
     */
49 3
    protected function createTables()
50
    {
51 3
        $this->createTable(ObjectAssociationRecord::tableName(), [
52 3
            'objectId' => $this->integer()->notNull(),
53 3
            'elementId' => $this->integer()->notNull(),
54 3
            'fieldId' => $this->integer()->notNull(),
55 3
            'siteId' => $this->integer()->notNull(),
56 3
            'sortOrder' => $this->smallInteger()->unsigned(),
57 3
            'dateCreated' => $this->dateTime()->notNull(),
58 3
            'dateUpdated' => $this->dateTime()->notNull(),
59 3
            'uid' => $this->uid()
60
        ]);
61 3
    }
62
63
    /**
64
     * Creates the indexes.
65
     *
66
     * @return void
67
     */
68 3
    protected function createIndexes()
69
    {
70 3
        $this->addPrimaryKey(
71 3
            null,
72 3
            ObjectAssociationRecord::tableName(),
73
            [
74 3
                'elementId',
75
                'objectId',
76
                'fieldId',
77
                'siteId'
78
            ]
79
        );
80 3
        $this->createIndex(
81 3
            null,
82 3
            ObjectAssociationRecord::tableName(),
83 3
            'objectId',
84 3
            false
85
        );
86 3
    }
87
88
    /**
89
     * Adds the foreign keys.
90
     *
91
     * @return void
92
     */
93 3
    protected function addForeignKeys()
94
    {
95 3
        $this->addForeignKey(
96 3
            null,
97 3
            ObjectAssociationRecord::tableName(),
98 3
            'elementId',
99 3
            ElementRecord::tableName(),
100 3
            'id',
101 3
            'CASCADE',
102 3
            null
103
        );
104
        $this->addForeignKey(
105
            null,
106
            ObjectAssociationRecord::tableName(),
107
            'siteId',
108
            SiteRecord::tableName(),
109
            'id',
110
            'CASCADE',
111
            'CASCADE'
112
        );
113
        $this->addForeignKey(
114
            null,
115
            ObjectAssociationRecord::tableName(),
116
            'fieldId',
117
            FieldRecord::tableName(),
118
            'id',
119
            'CASCADE',
120
            'CASCADE'
121
        );
122
    }
123
}
124