AlterEntitiesTable::up()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Uccello\Core\Database\Migrations\Migration;
6
7
class AlterEntitiesTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        if (!Schema::hasColumn($this->tablePrefix.'entities', 'creator_id')) {
17
            Schema::table($this->tablePrefix.'entities', function(Blueprint $table) {
18
                $table->unsignedInteger('creator_id')->nullable()->after('record_id');
19
20
                // Foreign keys
21
                $table->foreign('creator_id')->references('id')->on('users');
22
            });
23
        }
24
    }
25
26
    /**
27
     * Reverse the migrations.
28
     *
29
     * @return void
30
     */
31
    public function down()
32
    {
33
        Schema::table($this->tablePrefix.'entities', function(Blueprint $table) {
34
            $table->dropForeign($this->tablePrefix.'entities_creator_id_foreign');
35
36
            $table->dropColumn('creator_id');
37
        });
38
    }
39
}
40