-
Notifications
You must be signed in to change notification settings - Fork 330
/
create_bouncer_tables.php
94 lines (82 loc) · 3.14 KB
/
create_bouncer_tables.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
use Silber\Bouncer\Database\Models;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBouncerTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(Models::table('abilities'), function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('title')->nullable();
$table->integer('entity_id')->unsigned()->nullable();
$table->string('entity_type')->nullable();
$table->boolean('only_owned')->default(false);
$table->json('options')->nullable();
$table->integer('scope')->nullable()->index();
$table->timestamps();
});
Schema::create(Models::table('roles'), function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('title')->nullable();
$table->integer('level')->unsigned()->nullable();
$table->integer('scope')->nullable()->index();
$table->timestamps();
$table->unique(
['name', 'scope'],
'roles_name_unique'
);
});
Schema::create(Models::table('assigned_roles'), function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id')->unsigned()->index();
$table->integer('entity_id')->unsigned();
$table->string('entity_type');
$table->integer('restricted_to_id')->unsigned()->nullable();
$table->string('restricted_to_type')->nullable();
$table->integer('scope')->nullable()->index();
$table->index(
['entity_id', 'entity_type', 'scope'],
'assigned_roles_entity_index'
);
$table->foreign('role_id')
->references('id')->on(Models::table('roles'))
->onUpdate('cascade')->onDelete('cascade');
});
Schema::create(Models::table('permissions'), function (Blueprint $table) {
$table->increments('id');
$table->integer('ability_id')->unsigned()->index();
$table->integer('entity_id')->unsigned()->nullable();
$table->string('entity_type')->nullable();
$table->boolean('forbidden')->default(false);
$table->integer('scope')->nullable()->index();
$table->index(
['entity_id', 'entity_type', 'scope'],
'permissions_entity_index'
);
$table->foreign('ability_id')
->references('id')->on(Models::table('abilities'))
->onUpdate('cascade')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop(Models::table('permissions'));
Schema::drop(Models::table('assigned_roles'));
Schema::drop(Models::table('roles'));
Schema::drop(Models::table('abilities'));
}
}