]> BookStack Code Mirror - bookstack/blob - database/migrations/2016_10_09_142037_create_attachments_table.php
New translations entities.php (Portuguese, Brazilian)
[bookstack] / database / migrations / 2016_10_09_142037_create_attachments_table.php
1 <?php
2
3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\Schema;
6
7 class CreateAttachmentsTable extends Migration
8 {
9     /**
10      * Run the migrations.
11      *
12      * @return void
13      */
14     public function up()
15     {
16         Schema::create('attachments', function (Blueprint $table) {
17             $table->increments('id');
18             $table->string('name');
19             $table->string('path');
20             $table->string('extension', 20);
21             $table->integer('uploaded_to');
22
23             $table->boolean('external');
24             $table->integer('order');
25
26             $table->integer('created_by');
27             $table->integer('updated_by');
28
29             $table->index('uploaded_to');
30             $table->timestamps();
31         });
32
33         // Get roles with permissions we need to change
34         $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
35
36         // Create & attach new entity permissions
37         $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
38         $entity = 'Attachment';
39         foreach ($ops as $op) {
40             $permissionId = DB::table('role_permissions')->insertGetId([
41                 'name'         => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
42                 'display_name' => $op . ' ' . $entity . 's',
43                 'created_at'   => \Carbon\Carbon::now()->toDateTimeString(),
44                 'updated_at'   => \Carbon\Carbon::now()->toDateTimeString(),
45             ]);
46             DB::table('permission_role')->insert([
47                 'role_id'       => $adminRoleId,
48                 'permission_id' => $permissionId,
49             ]);
50         }
51     }
52
53     /**
54      * Reverse the migrations.
55      *
56      * @return void
57      */
58     public function down()
59     {
60         Schema::dropIfExists('attachments');
61
62         // Create & attach new entity permissions
63         $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
64         $entity = 'Attachment';
65         foreach ($ops as $op) {
66             $permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
67             DB::table('role_permissions')->where('name', '=', $permName)->delete();
68         }
69     }
70 }