20180514140000_revert_index_change_on_statuses_for_api_v1_accounts_account_id_statuses.rb 894 B

123456789101112131415
  1. # frozen_string_literal: true
  2. class RevertIndexChangeOnStatusesForApiV1AccountsAccountIdStatuses < ActiveRecord::Migration[5.2]
  3. disable_ddl_transaction!
  4. def change
  5. safety_assured do
  6. add_index :statuses, [:account_id, :id, :visibility, :updated_at], order: { id: :desc }, algorithm: :concurrently, name: :index_statuses_20180106 unless index_name_exists?(:statuses, 'index_statuses_20180106')
  7. end
  8. # These index may not exists (see migration 20180514130000)
  9. remove_index :statuses, column: [:account_id, :id, :visibility], where: 'visibility IN (0, 1, 2)', algorithm: :concurrently if index_exists?(:statuses, [:account_id, :id, :visibility], where: 'visibility IN (0, 1, 2)')
  10. remove_index :statuses, column: [:account_id, :id], where: 'visibility = 3', algorithm: :concurrently if index_exists?(:statuses, %w(account_id id), where: '(visibility = 3)')
  11. end
  12. end