scinote-web/db/migrate/20151021085335_add_search_query_indexes.rb

51 lines
1.5 KiB
Ruby
Raw Normal View History

2016-02-12 23:52:43 +08:00
require File.expand_path('app/helpers/database_helper')
include DatabaseHelper
2017-06-30 16:23:28 +08:00
class AddSearchQueryIndexes < ActiveRecord::Migration[4.2]
2016-02-12 23:52:43 +08:00
def up
2017-01-26 23:30:31 +08:00
add_index :projects, :team_id
add_index :user_teams, :user_id
add_index :user_teams, :team_id
2016-02-12 23:52:43 +08:00
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
# There's already semi-useless BTree index on samples
remove_index :samples, :name
add_gist_index :samples, :name
end
end
def down
2017-01-26 23:30:31 +08:00
remove_index :projects, :team_id
remove_index :user_teams, :user_id
remove_index :user_teams, :team_id
2016-02-12 23:52:43 +08:00
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
# Re-add semi-useless BTree index on samples
remove_index :samples, :name
add_index :samples, :name
end
end
end