defmodule WhoNeedHelp.Repo.Migrations.AddKeysetPaginationIndexes do
  use Ecto.Migration

  def change do
    create index(:help_requests, [:expires_at, :id],
             name: :help_requests_discovery_cursor_index,
             where: "status = 'open' AND hidden_at IS NULL"
           )

    create index(:help_requests, [:requester_id, :inserted_at, :id],
             name: :help_requests_requester_cursor_index
           )

    create index(:activities, [:starts_at, :id],
             name: :activities_discovery_cursor_index,
             where: "status = 'open' AND hidden_at IS NULL"
           )

    create index(:messages, [:assignment_id, :inserted_at, :id],
             name: :messages_assignment_cursor_index
           )

    create index(:activity_messages, [:activity_id, :inserted_at, :id],
             name: :activity_messages_activity_cursor_index
           )

    create index(:reviews, [:reviewee_id, :inserted_at, :id],
             name: :reviews_visible_cursor_index,
             where: "revealed_at IS NOT NULL"
           )

    create index(:reports, [:inserted_at, :id], name: :reports_cursor_index)

    create index(:blocks, [:blocker_id, :inserted_at, :id], name: :blocks_blocker_cursor_index)

    create index(:abuse_signals, [:status, :inserted_at, :id],
             name: :abuse_signals_status_cursor_index
           )

    create index(:category_proposals, [:inserted_at, :id], name: :category_proposals_cursor_index)

    create index(:users, [:inserted_at, :id], name: :users_moderation_cursor_index)
  end
end
