浏览代码

Add database indexes for objects using soft delete

leuc 6 年之前
父节点
当前提交
05b54564da
共有 1 个文件被更改,包括 88 次插入0 次删除
  1. 88 0
      database/migrations/2019_02_13_221138_add_soft_delete_indexes.php

+ 88 - 0
database/migrations/2019_02_13_221138_add_soft_delete_indexes.php

@@ -0,0 +1,88 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddSoftDeleteIndexes extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('avatars', function (Blueprint $table) {
+            $table->index('deleted_at','avatars_deleted_at_index');
+        });
+
+        Schema::table('profiles', function (Blueprint $table) {
+            $table->index('deleted_at','profiles_deleted_at_index');
+        });
+
+        Schema::table('mentions', function (Blueprint $table) {
+            $table->index('deleted_at','mentions_deleted_at_index');
+        });
+
+        Schema::table('likes', function (Blueprint $table) {
+            $table->index('deleted_at','likes_deleted_at_index');
+        });
+
+        Schema::table('statuses', function (Blueprint $table) {
+            $table->index('deleted_at','statuses_deleted_at_index');
+        });
+
+        Schema::table('media', function (Blueprint $table) {
+            $table->index('deleted_at','media_deleted_at_index');
+        });
+
+        Schema::table('notifications', function (Blueprint $table) {
+            $table->index('deleted_at','notifications_deleted_at_index');
+        });
+
+        Schema::table('users', function (Blueprint $table) {
+            $table->index('deleted_at','users_deleted_at_index');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('avatars', function (Blueprint $table) {
+            $table->dropIndex('deleted_at','avatars_deleted_at_index');
+        });
+
+        Schema::table('profiles', function (Blueprint $table) {
+            $table->dropIndex('deleted_at','profiles_deleted_at_index');
+        });
+
+        Schema::table('mentions', function (Blueprint $table) {
+            $table->dropIndex('deleted_at','mentions_deleted_at_index');
+        });
+
+        Schema::table('likes', function (Blueprint $table) {
+            $table->dropIndex('deleted_at','likes_deleted_at_index');
+        });
+
+        Schema::table('statuses', function (Blueprint $table) {
+            $table->dropIndex('deleted_at','statuses_deleted_at_index');
+        });
+
+        Schema::table('media', function (Blueprint $table) {
+            $table->dropIndex('deleted_at','media_deleted_at_index');
+        });
+
+        Schema::table('notifications', function (Blueprint $table) {
+            $table->dropIndex('deleted_at','notifications_deleted_at_index');
+        });
+
+        Schema::table('users', function (Blueprint $table) {
+            $table->dropIndex('deleted_at','users_deleted_at_index');
+        });
+    }
+}