m180310_090057_chg_proxy::safeDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
3
use yii\db\Migration;
4
5
/**
6
 * Class m180310_090057_chg_proxy
7
 */
8
class m180310_090057_chg_proxy extends Migration
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    public function safeUp()
14
    {
15
        $this->alterColumn('proxy', 'ip', $this->string()->notNull());
16
        $this->alterColumn('proxy', 'port', $this->integer()->notNull());
17
        $this->alterColumn('proxy', 'active', $this->boolean()->notNull()->defaultValue(1));
18
19
        $this->addColumn('proxy', 'default_for_accounts', $this->boolean()->notNull()->defaultValue('0'));
20
        $this->addColumn('proxy', 'default_for_tags', $this->boolean()->notNull()->defaultValue('0'));
21
22
        $this->dropColumn('proxy', 'type');
23
24
        $this->addColumn('account', 'proxy_tag_id', $this->integer()->after('proxy_id'));
25
        $this->addForeignKey('fk_account_proxy_tag', 'account', 'proxy_tag_id', 'tag', 'id', 'SET NULL');
26
27
        $this->addColumn('tag', 'proxy_tag_id', $this->integer()->after('proxy_id'));
28
        $this->addForeignKey('fk_tag_proxy_tag', 'tag', 'proxy_tag_id', 'tag', 'id', 'SET NULL');
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function safeDown()
35
    {
36
        $this->dropForeignKey('fk_account_proxy_tag', 'account');
37
        $this->dropColumn('account', 'proxy_tag_id');
38
39
        $this->dropForeignKey('fk_tag_proxy_tag', 'tag');
40
        $this->dropColumn('tag', 'proxy_tag_id');
41
42
        $this->addColumn('proxy', 'type', $this->string());
43
44
        $this->dropColumn('proxy', 'default_for_accounts');
45
        $this->dropColumn('proxy', 'default_for_tags');
46
    }
47
}
48