CreatePrivUserRoleTable::up()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 15
nc 1
nop 0
dl 0
loc 27
rs 9.7666
c 1
b 0
f 0
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
use Mrluke\Privileges\Facades\Manager;
8
9
class CreatePrivUserRoleTable extends Migration
10
{
11
    /**
12
     * Run the migrations.
13
     *
14
     * @return void
15
     */
16
    public function up()
17
    {
18
        $config = Manager::getAuthorizableMigration();
19
20
        Schema::create('priv_auth_role', function (Blueprint $table) use ($config) {
21
            // Depend on Authorizable table structure
22
            // package provides support for tree types
23
            // of primaryKey: integer, string & uuid.
24
            //
25
            if ($config['type'] == 'int') {
26
                $table->unsignedInteger('auth_id');
27
28
            } elseif ($config['type'] == 'string') {
29
                $table->string('auth_id');
30
31
            } elseif ($config['type'] == 'uuid') {
32
                $table->uuid('auth_id');
33
            }
34
            $table->unsignedInteger('role_id');
35
36
            $table->foreign('auth_id')
37
                  ->references($config['key'])->on($config['table'])
38
                  ->onDelete('CASCADE');
39
40
            $table->foreign('role_id')
41
                  ->references('id')->on('priv_roles')
42
                  ->onDelete('CASCADE');
43
        });
44
    }
45
46
    /**
47
     * Reverse the migrations.
48
     *
49
     * @return void
50
     */
51
    public function down()
52
    {
53
        Schema::disableForeignKeyConstraints();
54
55
        Schema::dropIfExists('priv_auth_role');
56
    }
57
}
58