scinote-web/db/migrate/20151021085335_add_search_query_indexes.rb
2016-02-12 16:52:43 +01:00

52 lines
1.6 KiB
Ruby

require File.expand_path('app/helpers/database_helper')
include DatabaseHelper
class AddSearchQueryIndexes < ActiveRecord::Migration
def up
add_index :projects, :organization_id
add_index :user_organizations, :user_id
add_index :user_organizations, :organization_id
add_index :user_projects, :user_id
add_index :user_projects, :project_id
add_index :tags, :project_id
# Add GIST trigram indexes onto columns that check for
# ILIKE %pattern% during search
if db_adapter_is? "PostgreSQL" then
add_gist_index :projects, :name
add_gist_index :my_modules, :name
add_gist_index :my_module_groups, :name
add_gist_index :tags, :name
add_gist_index :steps, :name
add_gist_index :results, :name
add_gist_index :assets, :file_file_name
# There's already semi-useless BTree index on samples
remove_index :samples, :name
add_gist_index :samples, :name
end
end
def down
remove_index :projects, :organization_id
remove_index :user_organizations, :user_id
remove_index :user_organizations, :organization_id
remove_index :user_projects, :user_id
remove_index :user_projects, :project_id
remove_index :tags, :project_id
if db_adapter_is? "PostgreSQL" then
remove_index :projects, :name
remove_index :my_modules, :name
remove_index :my_module_groups, :name
remove_index :tags, :name
remove_index :steps, :name
remove_index :results, :name
remove_index :assets, :file_file_name
# Re-add semi-useless BTree index on samples
remove_index :samples, :name
add_index :samples, :name
end
end
end