about summary refs log tree commit diff
path: root/db/migrate/20200227214439_modify_status_index.rb
blob: 2f4e98da5574b47011a831e84fae70e44d85e29b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class ModifyStatusIndex < ActiveRecord::Migration[5.2]
  def up
    remove_index :statuses, name: :index_statuses_20190820
    if index_exists? :statuses, name: :index_statuses_on_account_id_and_id_and_visibility_not_hidden
      remove_index :statuses, name: :index_statuses_on_account_id_and_id_and_visibility_not_hidden
    end

    remove_index :statuses, name: :index_statuses_on_account_id_and_id_and_visibility

    if index_exists? :statuses, name: :index_statuses_local_20190824
      remove_index :statuses, name: :index_statuses_local_20190824
    end

    safety_assured do
      add_index :statuses, [:account_id, :id, :visibility, :updated_at], where: '(deleted_at IS NULL) AND (NOT hidden)', order: { id: :desc }, name: :index_statuses_20200301
      add_index :statuses, [:id, :account_id], where: 'network AND (NOT hidden) AND ((local OR (uri IS NULL)) AND (deleted_at IS NULL) AND (visibility IN (0, 5)) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))', order: { id: :desc }, name: :index_statuses_local_20200301
      add_index :statuses, [:id, :account_id], where: '(NOT hidden) AND ((deleted_at IS NULL) AND (visibility in (0, 1, 5)) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))', order: { id: :desc }, name: :index_statuses_public_20200301
      add_index :statuses, [:id, :account_id], where: 'hidden', name: :index_statuses_hidden_20200301
    end
  end
end