diff --git a/db/migrate/20120709180215_add_attachment_indexes_for_sorting.rb b/db/migrate/20120709180215_add_attachment_indexes_for_sorting.rb index fc8943fce3f..0f00bde4bc3 100644 --- a/db/migrate/20120709180215_add_attachment_indexes_for_sorting.rb +++ b/db/migrate/20120709180215_add_attachment_indexes_for_sorting.rb @@ -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 diff --git a/db/migrate/20131105234428_fix_attachment_sorting_indexes.rb b/db/migrate/20131105234428_fix_attachment_sorting_indexes.rb new file mode 100644 index 00000000000..e30aed83269 --- /dev/null +++ b/db/migrate/20131105234428_fix_attachment_sorting_indexes.rb @@ -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