m181010_081033_provider_locks::safeDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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\records\Provider;
13
use flipbox\patron\records\ProviderLock;
14
15
class m181010_081033_provider_locks extends Migration
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public function safeUp()
21
    {
22
        $this->createTable(
23
            ProviderLock::tableName(),
24
            [
25
                'providerId' => $this->integer()->notNull(),
26
                'pluginId' => $this->integer()->notNull(),
27
                'dateCreated' => $this->dateTime()->notNull(),
28
                'dateUpdated' => $this->dateTime()->notNull(),
29
                'uid' => $this->uid(),
30
            ]
31
        );
32
33
        $this->addPrimaryKey(
34
            null,
35
            ProviderLock::tableName(),
36
            [
37
                'providerId',
38
                'pluginId'
39
            ]
40
        );
41
42
        $this->addForeignKey(
43
            $this->db->getForeignKeyName(
44
                ProviderLock::tableName(),
45
                'providerId'
46
            ),
47
            ProviderLock::tableName(),
48
            'providerId',
49
            Provider::tableName(),
50
            'id',
51
            'CASCADE'
52
        );
53
54
        $this->addForeignKey(
55
            $this->db->getForeignKeyName(
56
                ProviderLock::tableName(),
57
                'pluginId'
58
            ),
59
            ProviderLock::tableName(),
60
            'pluginId',
61
            '{{%plugins}}',
62
            'id',
63
            'CASCADE'
64
        );
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function safeDown()
71
    {
72
        $this->dropTableIfExists(ProviderLock::tableName());
73
74
        return true;
75
    }
76
}
77