CreateEntitiesTable::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 21
rs 9.8333
cc 1
nc 1
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 CreateEntitiesTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        Schema::create($this->tablePrefix.'entities', function (Blueprint $table) {
17
            $table->uuid('id')->primary();
18
            $table->unsignedInteger('module_id');
19
            $table->unsignedInteger('record_id');
20
            $table->unsignedInteger('creator_id')->nullable();
21
            $table->timestamps();
22
23
            $table->index('module_id', 'record_id');
24
25
            // Foreign keys
26
            $table->foreign('module_id')
27
                ->references('id')->on($this->tablePrefix.'modules')
28
                ->onDelete('cascade');
29
30
            $table->foreign('creator_id')
31
                ->references('id')->on('users');
32
33
            // Index
34
            $table->index(array('module_id', 'creator_id'));
35
        });
36
    }
37
38
    /**
39
     * Reverse the migrations.
40
     *
41
     * @return void
42
     */
43
    public function down()
44
    {
45
        Schema::dropIfExists($this->tablePrefix.'entities');
46
    }
47
}
48