AddTrackerRefererColumns::migrateUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use PragmaRX\Tracker\Support\Migration;
4
5
class AddTrackerRefererColumns extends Migration
6
{
7
    /**
8
     * Table related to this migration.
9
     *
10
     * @var string
11
     */
12
    private $table = 'tracker_referers';
13
14
    private $foreign = 'tracker_referers_search_terms';
15
16
    /**
17
     * Run the migrations.
18
     *
19
     * @return void
20
     */
21
    public function migrateUp()
22
    {
23
        $this->builder->table(
24
            $this->table,
25
            function ($table) {
26
                $table->string('medium')->nullable()->index();
27
                $table->string('source')->nullable()->index();
28
                $table->string('search_terms_hash')->nullable()->index();
29
            }
30
        );
31
32
        $this->builder->table($this->foreign, function ($table) {
33
            $table->foreign('referer_id', 'tracker_referers_referer_id_fk')
34
                ->references('id')
35
                ->on('tracker_referers')
36
                ->onUpdate('cascade')
37
                ->onDelete('cascade');
38
        });
39
    }
40
41
    /**
42
     * Reverse the migrations.
43
     *
44
     * @return void
45
     */
46
    public function migrateDown()
47
    {
48
        $this->builder->table(
49
            $this->table,
50
            function ($table) {
51
                $table->dropColumn('medium');
52
                $table->dropColumn('source');
53
                $table->dropColumn('search_terms_hash');
54
            }
55
        );
56
57
        $this->builder->table(
58
            $this->foreign,
59
            function ($table) {
60
                $table->dropForeign('tracker_referers_referer_id_fk');
61
            }
62
        );
63
    }
64
}
65