<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddIndexesToPosts extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->index('created_at');
            $table->index(['status', 'deleted_at']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->dropIndex('posts_status_deleted_at_index');
            $table->dropIndex('posts_created_at_index');
        });
    }
}

Add index to posts 'created_at' and 'deleted_at' columns. This significantly speeds up the ORDER BY query being made in the PostsController (especially if using cursor pagination).
Add index to posts 'created_at' and 'deleted_at' columns.
This significantly speeds up the ORDER BY query being made
in the PostsController (especially if using cursor pagination).
