]> BookStack Code Mirror - bookstack/blob - database/migrations/2020_08_04_131052_remove_role_name_field.php
f3cafb7323280eb2aeb58d3dfd7f9bd3df1881c1
[bookstack] / database / migrations / 2020_08_04_131052_remove_role_name_field.php
1 <?php
2
3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\Schema;
6 use Illuminate\Support\Facades\DB;
7
8 class RemoveRoleNameField extends Migration
9 {
10     /**
11      * Run the migrations.
12      *
13      * @return void
14      */
15     public function up()
16     {
17         Schema::table('roles', function (Blueprint $table) {
18             $table->dropColumn('name');
19         });
20     }
21
22     /**
23      * Reverse the migrations.
24      *
25      * @return void
26      */
27     public function down()
28     {
29         Schema::table('roles', function (Blueprint $table) {
30             $table->string('name')->index();
31         });
32
33         DB::table('roles')->update([
34             "name" => DB::raw("lower(replace(`display_name`, ' ', '-'))"),
35         ]);
36     }
37 }