CreatePermissionsTable::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 24
rs 9.7333
c 0
b 0
f 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 CreatePermissionsTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        Schema::create($this->tablePrefix.'permissions', function(Blueprint $table) {
17
            $table->increments('id');
18
            $table->unsignedInteger('module_id');
19
            $table->unsignedInteger('profile_id');
20
            $table->unsignedInteger('capability_id');
21
            $table->timestamps();
22
23
            // Foreign keys
24
            $table->foreign('module_id')
25
                    ->references('id')->on($this->tablePrefix.'modules')
26
                    ->onDelete('cascade');
27
28
            $table->foreign('profile_id')
29
                    ->references('id')->on($this->tablePrefix.'profiles')
30
                    ->onDelete('cascade');
31
32
            $table->foreign('capability_id')
33
                    ->references('id')->on($this->tablePrefix.'capabilities')
34
                    ->onDelete('cascade');
35
36
            // Unique keys
37
            $table->unique([ 'module_id', 'profile_id', 'capability_id' ]);
38
        });
39
    }
40
41
    /**
42
     * Reverse the migrations.
43
     *
44
     * @return void
45
     */
46
    public function down()
47
    {
48
        Schema::dropIfExists($this->tablePrefix.'permissions');
49
    }
50
}
51