fix attachments sorting indexes

refs CNVS-5180

Change-Id: Idb1e0e75c71953d365a7faa54d6eea332c6bc5c9
Reviewed-on: https://gerrit.instructure.com/26029
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2013-11-06 09:08:55 -07:00
parent 2581cce3c3
commit d2db6ead45
2 changed files with 15 additions and 2 deletions

View File

@ -15,11 +15,11 @@ class AddAttachmentIndexesForSorting < ActiveRecord::Migration
end
add_index :attachments, [:folder_id, :file_state, :position], :algorithm => :concurrently
remove_index :attachments, "index_attachments_on_folder_id"
remove_index :attachments, :folder_id
end
def self.down
add_index :attachments, [:folder_id], :name => "index_attachments_on_folder_id"
add_index :attachments, :folder_id, algorithm: :concurrently
remove_index :attachments, "index_attachments_on_folder_id_and_file_state_and_display_name"
remove_index :attachments, "index_attachments_on_folder_id_and_file_state_and_position"
end

View File

@ -0,0 +1,13 @@
class FixAttachmentSortingIndexes < ActiveRecord::Migration
tag :postdeploy
disable_ddl_transaction!
def self.up
if connection.adapter_name == 'PostgreSQL' && connection.select_value("SELECT 1 FROM pg_index WHERE indexrelid='index_attachments_on_folder_id_and_file_state_and_position'::regclass AND indpred IS NOT NULL")
execute("ALTER INDEX index_attachments_on_folder_id_and_file_state_and_position RENAME TO index_attachments_on_folder_id_and_file_state_and_position2")
add_index :attachments, [:folder_id, :file_state, :position], :algorithm => :concurrently
remove_index :attachments, name: 'index_attachments_on_folder_id_and_file_state_and_position2'
end
remove_index :attachments, :folder_id
end
end