]> BookStack Code Mirror - bookstack/commitdiff
Updated entity_permissions table for user perms.
authorDan Brown <redacted>
Wed, 7 Dec 2022 14:57:23 +0000 (14:57 +0000)
committerDan Brown <redacted>
Wed, 7 Dec 2022 14:57:23 +0000 (14:57 +0000)
As start of user permissions work

database/migrations/2022_12_07_113821_add_user_id_to_entity_permissions.php [new file with mode: 0644]

diff --git a/database/migrations/2022_12_07_113821_add_user_id_to_entity_permissions.php b/database/migrations/2022_12_07_113821_add_user_id_to_entity_permissions.php
new file mode 100644 (file)
index 0000000..9fd9c61
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+class AddUserIdToEntityPermissions extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('entity_permissions', function (Blueprint $table) {
+            $table->unsignedInteger('role_id')->nullable()->default(null)->change();
+            $table->unsignedInteger('user_id')->nullable()->default(null)->index();
+        });
+
+        DB::table('entity_permissions')
+            ->where('role_id', '=', 0)
+            ->update(['role_id' => null]);
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        DB::table('entity_permissions')
+            ->whereNull('role_id')
+            ->update(['role_id' => 0]);
+
+        DB::table('entity_permissions')
+            ->whereNotNull('user_id')
+            ->delete();
+
+        Schema::table('entity_permissions', function (Blueprint $table) {
+            $table->unsignedInteger('role_id')->nullable(false)->change();
+            $table->dropColumn('user_id');
+        });
+    }
+}