Completed
Push — master ( e45dbf...3a73d5 )
by Nate
05:43 queued 04:08
created

m180716_121422_environments   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 8
dl 0
loc 87
ccs 0
cts 72
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B safeUp() 0 72 1
A safeDown() 0 5 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\migrations;
10
11
use craft\db\Migration;
12
use flipbox\patron\Patron;
13
use flipbox\patron\records\Provider;
14
use flipbox\patron\records\ProviderEnvironment;
15
use flipbox\patron\records\Token;
16
use flipbox\patron\records\TokenEnvironment;
17
18
class m180716_121422_environments extends Migration
19
{
20
    /**
21
     * @inheritdoc
22
     */
23
    public function safeUp()
24
    {
25
        $this->createTable(
26
            ProviderEnvironment::tableName(),
27
            [
28
                'providerId' => $this->integer()->notNull(),
29
                'environment' => $this->enum(
30
                    'environment',
31
                    Patron::getInstance()->getSettings()->getEnvironments()
32
                )->notNull(),
33
                'dateCreated' => $this->dateTime()->notNull(),
34
                'dateUpdated' => $this->dateTime()->notNull(),
35
                'uid' => $this->uid(),
36
            ]
37
        );
38
39
        $this->createTable(
40
            TokenEnvironment::tableName(),
41
            [
42
                'tokenId' => $this->integer()->notNull(),
43
                'environment' => $this->enum(
44
                    'environment',
45
                    Patron::getInstance()->getSettings()->getEnvironments()
46
                )->notNull(),
47
                'dateCreated' => $this->dateTime()->notNull(),
48
                'dateUpdated' => $this->dateTime()->notNull(),
49
                'uid' => $this->uid(),
50
            ]
51
        );
52
53
        $this->addPrimaryKey(
54
            null,
55
            ProviderEnvironment::tableName(),
56
            [
57
                'providerId',
58
                'environment'
59
            ]
60
        );
61
62
        $this->addForeignKey(
63
            $this->db->getForeignKeyName(
64
                ProviderEnvironment::tableName(),
65
                'providerId'
66
            ),
67
            ProviderEnvironment::tableName(),
68
            'providerId',
69
            Provider::tableName(),
70
            'id',
71
            'CASCADE'
72
        );
73
74
        $this->addPrimaryKey(
75
            null,
76
            TokenEnvironment::tableName(),
77
            [
78
                'tokenId',
79
                'environment'
80
            ]
81
        );
82
83
        $this->addForeignKey(
84
            $this->db->getForeignKeyName(
85
                TokenEnvironment::tableName(),
86
                'tokenId'
87
            ),
88
            TokenEnvironment::tableName(),
89
            'tokenId',
90
            Token::tableName(),
91
            'id',
92
            'CASCADE'
93
        );
94
    }
95
96
    /**
97
     * @inheritdoc
98
     */
99
    public function safeDown()
100
    {
101
        echo "m180716_121422_environments cannot be reverted.\n";
102
        return false;
103
    }
104
}
105