]> BookStack Code Mirror - bookstack/blob - database/migrations/2016_02_28_084200_add_entity_access_controls.php
7a796e728d234f32edb4f7325e254a8d6d0cd65e
[bookstack] / database / migrations / 2016_02_28_084200_add_entity_access_controls.php
1 <?php
2
3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5
6 return new class extends Migration
7 {
8     /**
9      * Run the migrations.
10      *
11      * @return void
12      */
13     public function up()
14     {
15         Schema::table('images', function (Blueprint $table) {
16             $table->integer('uploaded_to')->default(0);
17             $table->index('uploaded_to');
18         });
19
20         Schema::table('books', function (Blueprint $table) {
21             $table->boolean('restricted')->default(false);
22             $table->index('restricted');
23         });
24
25         Schema::table('chapters', function (Blueprint $table) {
26             $table->boolean('restricted')->default(false);
27             $table->index('restricted');
28         });
29
30         Schema::table('pages', function (Blueprint $table) {
31             $table->boolean('restricted')->default(false);
32             $table->index('restricted');
33         });
34
35         Schema::create('restrictions', function (Blueprint $table) {
36             $table->increments('id');
37             $table->integer('restrictable_id');
38             $table->string('restrictable_type');
39             $table->integer('role_id');
40             $table->string('action');
41             $table->index('role_id');
42             $table->index('action');
43             $table->index(['restrictable_id', 'restrictable_type']);
44         });
45     }
46
47     /**
48      * Reverse the migrations.
49      *
50      * @return void
51      */
52     public function down()
53     {
54         Schema::table('images', function (Blueprint $table) {
55             $table->dropColumn('uploaded_to');
56         });
57
58         Schema::table('books', function (Blueprint $table) {
59             $table->dropColumn('restricted');
60         });
61
62         Schema::table('chapters', function (Blueprint $table) {
63             $table->dropColumn('restricted');
64         });
65
66         Schema::table('pages', function (Blueprint $table) {
67             $table->dropColumn('restricted');
68         });
69
70         Schema::drop('restrictions');
71     }
72 };