]> BookStack Code Mirror - bookstack/commitdiff
Merged comment migrations and incremented dev version
authorDan Brown <redacted>
Tue, 1 Aug 2017 19:05:49 +0000 (20:05 +0100)
committerDan Brown <redacted>
Tue, 1 Aug 2017 19:05:49 +0000 (20:05 +0100)
database/migrations/2017_01_01_130541_create_comments_table.php [deleted file]
database/migrations/2017_06_04_060012_comments_add_active_col.php [deleted file]
database/migrations/2017_08_01_130541_create_comments_table.php [new file with mode: 0644]
version

diff --git a/database/migrations/2017_01_01_130541_create_comments_table.php b/database/migrations/2017_01_01_130541_create_comments_table.php
deleted file mode 100644 (file)
index f4ece31..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-
-use Illuminate\Support\Facades\Schema;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Database\Migrations\Migration;
-
-class CreateCommentsTable extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        if (Schema::hasTable('comments')) {
-            return;
-        }
-        Schema::create('comments', function (Blueprint $table) {
-            $table->increments('id')->unsigned();
-            $table->integer('page_id')->unsigned();
-            $table->longText('text')->nullable();
-            $table->longText('html')->nullable();
-            $table->integer('parent_id')->unsigned()->nullable();
-            $table->integer('created_by')->unsigned();
-            $table->integer('updated_by')->unsigned()->nullable();
-            $table->index(['page_id', 'parent_id']);
-            $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'];
-            $entity = 'Comment';
-            foreach ($ops as $op) {
-                $permissionId = DB::table('role_permissions')->insertGetId([
-                    'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
-                    'display_name' => $op . ' ' . $entity . 's',
-                    'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
-                    'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
-                ]);
-                DB::table('permission_role')->insert([
-                    'role_id' => $adminRoleId,
-                    'permission_id' => $permissionId
-                ]);
-            }
-
-            // Get roles with permissions we need to change
-            /*
-            $editorRole = DB::table('roles')->where('name', '=', 'editor')->first();
-            if (!empty($editorRole)) {
-                $editorRoleId = $editorRole->id;
-                // Create & attach new entity permissions
-                $ops = ['Create All', 'Create Own', 'Update Own', 'Delete Own'];
-                $entity = 'Comment';
-                foreach ($ops as $op) {
-                    $permissionId = DB::table('role_permissions')->insertGetId([
-                        'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
-                        'display_name' => $op . ' ' . $entity . 's',
-                        'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
-                        'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
-                    ]);
-                    DB::table('permission_role')->insert([
-                        'role_id' => $editorRoleId,
-                        'permission_id' => $permissionId
-                    ]);
-                }
-            }
-
-            // Get roles with permissions we need to change
-            $viewerRole = DB::table('roles')->where('name', '=', 'viewer')->first();
-            if (!empty($viewerRole)) {
-                $viewerRoleId = $viewerRole->id;
-                // Create & attach new entity permissions
-                $ops = ['Create All'];
-                $entity = 'Comment';
-                foreach ($ops as $op) {
-                    $permissionId = DB::table('role_permissions')->insertGetId([
-                        'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
-                        'display_name' => $op . ' ' . $entity . 's',
-                        'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
-                        'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
-                    ]);
-                    DB::table('permission_role')->insert([
-                        'role_id' => $viewerRoleId,
-                        'permission_id' => $permissionId
-                    ]);
-                }
-            }
-            */
-
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::dropIfExists('comments');
-        // Create & attach new entity permissions
-        $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
-        $entity = 'Comment';
-        foreach ($ops as $op) {
-            $permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
-            DB::table('role_permissions')->where('name', '=', $permName)->delete();
-        }
-    }
-}
diff --git a/database/migrations/2017_06_04_060012_comments_add_active_col.php b/database/migrations/2017_06_04_060012_comments_add_active_col.php
deleted file mode 100644 (file)
index 3c6dd1f..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-
-use Illuminate\Support\Facades\Schema;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Database\Migrations\Migration;
-
-class CommentsAddActiveCol extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::table('comments', function (Blueprint $table) {
-            // add column active
-            $table->boolean('active')->default(true);
-            $table->dropIndex('comments_page_id_parent_id_index');
-            $table->index(['page_id']);
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::table('comments', function (Blueprint $table) {
-            // reversing the schema
-            $table->dropIndex('comments_page_id_index');
-            $table->dropColumn('active');
-            $table->index(['page_id', 'parent_id']);
-        });
-    }
-}
diff --git a/database/migrations/2017_08_01_130541_create_comments_table.php b/database/migrations/2017_08_01_130541_create_comments_table.php
new file mode 100644 (file)
index 0000000..bfb7eec
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateCommentsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('comments', function (Blueprint $table) {
+            $table->increments('id')->unsigned();
+            $table->integer('page_id')->unsigned();
+            $table->longText('text')->nullable();
+            $table->longText('html')->nullable();
+            $table->integer('parent_id')->unsigned()->nullable();
+            $table->integer('created_by')->unsigned();
+            $table->integer('updated_by')->unsigned()->nullable();
+            $table->boolean('active')->default(true);
+
+            $table->index(['page_id']);
+            $table->timestamps();
+
+            // Assign new comment permissions to admin role
+            $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'];
+            $entity = 'Comment';
+            foreach ($ops as $op) {
+                $permissionId = DB::table('role_permissions')->insertGetId([
+                    'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)),
+                    'display_name' => $op . ' ' . $entity . 's',
+                    'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
+                    'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
+                ]);
+                DB::table('permission_role')->insert([
+                    'role_id' => $adminRoleId,
+                    'permission_id' => $permissionId
+                ]);
+            }
+
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('comments');
+        // Delete comment role permissions
+        $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
+        $entity = 'Comment';
+        foreach ($ops as $op) {
+            $permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
+            DB::table('role_permissions')->where('name', '=', $permName)->delete();
+        }
+    }
+}
diff --git a/version b/version
index 1365ed940e528b43dbfb462c1f168179542614f9..de0ad77915bab6a1a85aa60ba37a325637f2ada4 100644 (file)
--- a/version
+++ b/version
@@ -1 +1 @@
-v0.17-dev
+v0.18-dev