diff --git a/db/migrate/20170407082423_add_team_id_to_steps.rb b/db/migrate/20170407082423_update_indexes_for_faster_search.rb similarity index 78% rename from db/migrate/20170407082423_add_team_id_to_steps.rb rename to db/migrate/20170407082423_update_indexes_for_faster_search.rb index c070a78f3..f5a4013da 100644 --- a/db/migrate/20170407082423_add_team_id_to_steps.rb +++ b/db/migrate/20170407082423_update_indexes_for_faster_search.rb @@ -1,43 +1,62 @@ require File.expand_path('app/helpers/database_helper') include DatabaseHelper -class AddTeamIdToSteps < ActiveRecord::Migration +class UpdateIndexesForFasterSearch < ActiveRecord::Migration def up if db_adapter_is? 'PostgreSQL' # Removing old indexes remove_index :projects, :name if index_exists?(:projects, :name) remove_index :my_modules, :name if index_exists?(:my_modules, :name) - remove_index :my_modules, :description if index_exists?(:my_modules, :description) + if index_exists?(:my_modules, :description) + remove_index :my_modules, :description + end remove_index :protocols, :name if index_exists?(:protocols, :name) - remove_index :protocols, :description if index_exists?(:protocols, :description) + if index_exists?(:protocols, :description) + remove_index :protocols, :description + end remove_index :protocols, :authors if index_exists?(:protocols, :authors) - remove_index :protocol_keywords, :name if index_exists?(:protocol_keywords, :name) - remove_index :my_module_groups, :name if index_exists?(:my_module_groups, :name) + if index_exists?(:protocol_keywords, :name) + remove_index :protocol_keywords, :name + end + if index_exists?(:my_module_groups, :name) + remove_index :my_module_groups, :name + end remove_index :tags, :name if index_exists?(:tags, :name) remove_index :results, :name if index_exists?(:results, :name) remove_index :result_texts, :text if index_exists?(:result_texts, :text) remove_index :reports, :name if index_exists?(:reports, :name) - remove_index :reports, :description if index_exists?(:reports, :description) - remove_index :assets, :file_file_name if index_exists?(:assets, :file_file_name) + if index_exists?(:reports, :description) + remove_index :reports, :description + end + if index_exists?(:assets, :file_file_name) + remove_index :assets, :file_file_name + end remove_index :samples, :name if index_exists?(:samples, :name) remove_index :sample_types, :name if index_exists?(:sample_types, :name) remove_index :sample_groups, :name if index_exists?(:sample_groups, :name) - remove_index :sample_custom_fields, :value if index_exists?(:sample_custom_fields, :value) + if index_exists?(:sample_custom_fields, :value) + remove_index :sample_custom_fields, :value + end remove_index :steps, :name if index_exists?(:steps, :name) remove_index :steps, :description if index_exists?(:steps, :description) remove_index :checklists, :name if index_exists?(:checklists, :name) - remove_index :checklist_items, :text if index_exists?(:checklist_items, :text) + if index_exists?(:checklist_items, :text) + remove_index :checklist_items, :text + end remove_index :tables, :name if index_exists?(:tables, :name) remove_index :users, :full_name if index_exists?(:users, :full_name) remove_index :comments, :message if index_exists?(:comments, :message) remove_index :comments, :type if index_exists?(:comments, :type) - remove_index :protocols, :protocol_type if index_exists?(:protocols, :protocol_type) + if index_exists?(:protocols, :protocol_type) + remove_index :protocols, :protocol_type + end remove_index :checklists, :step_id if index_exists?(:checklists, :step_id) execute( - "CREATE OR REPLACE FUNCTION trim_html_tags(IN input TEXT, OUT output TEXT) AS $$ + "CREATE OR REPLACE FUNCTION + trim_html_tags(IN input TEXT, OUT output TEXT) AS $$ SELECT regexp_replace(input, - E'<.*?>|\\\\[#.*\\\\]|\\\\[@.*\\\\]', + E'<[^>]*>|\\\\[#.*\\\\]|\\\\[@.*\\\\]', '', 'g'); $$ LANGUAGE SQL;" @@ -56,7 +75,7 @@ class AddTeamIdToSteps < ActiveRecord::Migration add_gin_index_without_tags :result_texts, :text add_gin_index_without_tags :reports, :name add_gin_index_without_tags :reports, :description - add_gist_index :assets, :file_file_name + add_gin_index_without_tags :assets, :file_file_name add_gin_index_without_tags :samples, :name add_gin_index_without_tags :sample_types, :name add_gin_index_without_tags :sample_groups, :name