|
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
|
|
|
} |