Completed
Push — master ( b985db...bee0c3 )
by Christian
05:14
created

CreateSpatieModelHasRolesTable::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
class CreateSpatieModelHasRolesTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14 51
    public function up()
15
    {
16 51
        $tableNames = config('permission.table_names');
17 51
        $columnNames = config('permission.column_names');
18
19
        Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) {
20 51
            $table->unsignedBigInteger('role_id');
21 51
            $table->string('model_type');
22 51
            $table->unsignedBigInteger($columnNames['model_morph_key']);
23 51
            $table->index([$columnNames['model_morph_key'], 'model_type',]);
24 51
            $table->foreign('role_id')
25 51
                ->references('id')
26 51
                ->on($tableNames['roles'])
27 51
                ->onDelete('cascade');
28 51
            $table->primary(
29 51
                ['role_id', $columnNames['model_morph_key'], 'model_type'],
30 51
                'model_has_roles_role_model_type_primary'
31
            );
32 51
        });
33
34 51
        app('cache')
35 51
            ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
36 51
            ->forget(config('permission.cache.key'));
37 51
    }
38
39
    /**
40
     * Reverse the migrations.
41
     *
42
     * @return void
43
     */
44 51
    public function down()
45
    {
46 51
        $tableNames = config('permission.table_names');
47
48 51
        Schema::drop($tableNames['model_has_roles']);
49 51
    }
50
}
51