Completed
Push — master ( a20c7b...d885ca )
by Nate
02:36
created

Install   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 6
dl 0
loc 65
ccs 0
cts 54
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B safeUp() 0 59 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-element-lists/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-element-lists/
7
 */
8
9
namespace flipbox\craft\element\lists\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\element\lists\records\Association;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class Install extends Migration
22
{
23
    /**
24
     * @inheritdoc
25
     */
26
    public function safeUp()
27
    {
28
        $this->createTable(Association::tableName(), [
29
            'fieldId' => $this->integer()->notNull(),
30
            'sourceId' => $this->integer()->notNull(),
31
            'targetId' => $this->integer()->notNull(),
32
            'siteId' => $this->integer()->notNull(),
33
            'sortOrder' => $this->integer()->unsigned(),
34
            'dateCreated' => $this->dateTime()->notNull(),
35
            'dateUpdated' => $this->dateTime()->notNull(),
36
            'uid' => $this->uid(),
37
        ]);
38
39
        $this->addPrimaryKey(
40
            null,
41
            Association::tableName(),
42
            ['fieldId', 'sourceId', 'targetId', 'siteId']
43
        );
44
45
        $this->addForeignKey(
46
            null,
47
            Association::tableName(),
48
            'fieldId',
49
            Field::tableName(),
50
            'id',
51
            'CASCADE',
52
            null
53
        );
54
55
        $this->addForeignKey(
56
            null,
57
            Association::tableName(),
58
            'sourceId',
59
            Element::tableName(),
60
            'id',
61
            'CASCADE',
62
            null
63
        );
64
65
        $this->addForeignKey(
66
            null,
67
            Association::tableName(),
68
            'targetId',
69
            Element::tableName(),
70
            'id',
71
            'CASCADE',
72
            null
73
        );
74
75
        $this->addForeignKey(
76
            null,
77
            Association::tableName(),
78
            'siteId',
79
            Site::tableName(),
80
            'id',
81
            'CASCADE',
82
            'CASCADE'
83
        );
84
    }
85
}
86