FixAgentName::migrateUp()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 2
nc 4
nop 0
1
<?php
2
3
use PragmaRX\Tracker\Support\Migration;
4
5
class FixAgentName extends Migration
6
{
7
    /**
8
     * Table related to this migration.
9
     *
10
     * @var string
11
     */
12
    private $table = 'tracker_agents';
13
14
    /**
15
     * Run the migrations.
16
     *
17
     * @return void
18
     */
19
    public function migrateUp()
20
    {
21
        try {
22
            $this->builder->table(
23
                $this->table,
24
                function ($table) {
25
                    $table->dropUnique('tracker_agents_name_unique');
26
                }
27
            );
28
29
            $this->builder->table(
30
                $this->table,
31
                function ($table) {
32
                    $table->mediumText('name')->change();
33
                }
34
            );
35
36
            $this->builder->table(
37
                $this->table,
38
                function ($table) {
39
                    $table->unique('id', 'tracker_agents_name_unique'); // this is a dummy index
40
                }
41
            );
42
        } catch (\Exception $e) {
43
            dd($e->getMessage());
44
        }
45
    }
46
47
    /**
48
     * Reverse the migrations.
49
     *
50
     * @return void
51
     */
52
    public function migrateDown()
53
    {
54
        try {
55
            $this->builder->table(
56
                $this->table,
57
                function ($table) {
58
                    $table->string('name', 255)->change();
59
                    $table->unique('name');
60
                }
61
            );
62
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
63
        }
64
    }
65
}
66