RoleMigration   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 54
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 6 1
B up() 0 37 1
1
<?php
2
3
use Phpmig\Migration\Migration;
4
use Illuminate\Database\Capsule\Manager as Capsule;
5
6
class RoleMigration extends Migration
7
{
8
    /**
9
     * Do the migration
10
     */
11
    public function up()
12
    {
13
14
        Capsule::schema()->create('roles', function($table) {
15
            $table->increments('id');
16
            $table->string('name')->unique();
17
            $table->string('display_name')->nullable();
18
            $table->string('description')->nullable();
19
            $table->timestamps();
20
        });
21
22
23
        Capsule::schema()->create('role_user', function($table) {
24
            $table->integer('user_id')->unsigned();
25
            $table->integer('role_id')->unsigned();
26
27
            $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');
28
            $table->foreign('role_id')->references('id')->on('roles')->onUpdate('cascade')->onDelete('cascade');
29
            $table->primary(['user_id', 'role_id']);
30
        });
31
32
        Capsule::schema()->create('permissions', function($table) {
33
            $table->increments('id');
34
            $table->string('name')->unique();
35
            $table->string('display_name')->nullable();
36
            $table->string('description')->nullable();
37
            $table->timestamps();
38
        });
39
40
        Capsule::schema()->create('permission_role', function($table) {
41
            $table->integer('permission_id')->unsigned();
42
            $table->integer('role_id')->unsigned();
43
44
            $table->foreign('permission_id')->references('id')->on('permissions')->onUpdate('cascade')->onDelete('cascade');
45
            $table->foreign('role_id')->references('id')->on('roles')->onUpdate('cascade')->onDelete('cascade');
46
47
            $table->primary(['permission_id', 'role_id']);
48
        });
49
    }
50
51
    /**
52
     * Undo the migration
53
     */
54
    public function down()
55
    {
56
        Capsule::schema()->drop('roles');
57
        Capsule::schema()->drop('role_user');
58
        Capsule::schema()->drop('permissions');
59
        Capsule::schema()->drop('permission_role');
60
    }
61
}