BookStack/database/migrations/2016_10_09_142037_create_attachments_table.php

71 lines
2.3 KiB
PHP
Raw Normal View History

<?php
use Illuminate\Database\Migrations\Migration;
2021-06-26 17:23:15 +02:00
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
2016-11-12 15:12:26 +01:00
Schema::create('attachments', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('path');
$table->string('extension', 20);
$table->integer('uploaded_to');
$table->boolean('external');
$table->integer('order');
$table->integer('created_by');
$table->integer('updated_by');
$table->index('uploaded_to');
$table->timestamps();
});
// Get roles with permissions we need to change
$adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
// Create & attach new entity permissions
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
2016-11-12 15:12:26 +01:00
$entity = 'Attachment';
foreach ($ops as $op) {
$permissionId = DB::table('role_permissions')->insertGetId([
2021-06-26 17:23:15 +02:00
'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
'display_name' => $op . ' ' . $entity . 's',
2021-06-26 17:23:15 +02:00
'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
'updated_at' => \Carbon\Carbon::now()->toDateTimeString(),
]);
DB::table('permission_role')->insert([
2021-06-26 17:23:15 +02:00
'role_id' => $adminRoleId,
'permission_id' => $permissionId,
]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
2016-11-12 15:12:26 +01:00
Schema::dropIfExists('attachments');
// Create & attach new entity permissions
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
2016-11-12 15:12:26 +01:00
$entity = 'Attachment';
foreach ($ops as $op) {
$permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
DB::table('role_permissions')->where('name', '=', $permName)->delete();
}
}
};