Completed
Pull Request — master (#186)
by Vladimir
16:33 queued 13:26
created

BansStatusColumnConversion::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
4
use Phinx\Migration\AbstractMigration;
5
6
class BansStatusColumnConversion extends AbstractMigration
7
{
8
    public function up()
9
    {
10
        $bansTable = $this->table('bans');
11
        $bansTable
12
            ->addColumn('is_deleted', 'boolean', [
13
                'after' => 'is_soft_ban',
14
                'null' => false,
15
                'default' => false,
16
                'comment' => 'Whether or not the ban has been deleted',
17
            ])
18
            ->update()
19
        ;
20
21
        $this->query("UPDATE bans SET is_deleted = 1 WHERE status = 'deleted';");
22
23
        $bansTable
24
            ->removeColumn('status')
25
            ->update()
26
        ;
27
    }
28
29
    public function down()
30
    {
31
        $bansTable = $this->table('bans');
32
        $bansTable
33
            ->addColumn('status', 'set', [
34
                'values' => ['public', 'hidden', 'deleted'],
35
                'after' => 'is_soft_ban',
36
                'null' => false,
37
                'default' => 'public',
38
                'comment' => 'The status of the ban element',
39
            ])
40
            ->update()
41
        ;
42
43
        $this->query("UPDATE bans SET status = 'deleted' WHERE is_deleted = true;");
44
45
        $bansTable
46
            ->removeColumn('is_deleted')
47
            ->update()
48
        ;
49
    }
50
}
51