Skip to content

Commit

Permalink
use gin for user search indexes
Browse files Browse the repository at this point in the history
refs #CORE-1447

Change-Id: I92a2ca98b16aedec3a956d18287a82f0b6ccf1aa
Reviewed-on: https://gerrit.instructure.com/152192
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <[email protected]>
Product-Review: James Williams  <[email protected]>
QA-Review: James Williams  <[email protected]>
  • Loading branch information
maneframe committed Jun 4, 2018
1 parent 6b7e71a commit ee9ad6c
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions db/migrate/20180601153421_replace_user_search_indexes_with_gin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Copyright (C) 2014 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

class ReplaceUserSearchIndexesWithGin < ActiveRecord::Migration[5.1]
tag :postdeploy
disable_ddl_transaction!

def up
if (schema = connection.extension_installed?(:pg_trgm))
add_index :users, "lower(name) #{schema}.gin_trgm_ops", name: "index_gin_trgm_users_name", using: :gin, algorithm: :concurrently
add_index :pseudonyms, "lower(sis_user_id) #{schema}.gin_trgm_ops", name: "index_gin_trgm_pseudonyms_sis_user_id", using: :gin, algorithm: :concurrently
add_index :communication_channels, "lower(path) #{schema}.gin_trgm_ops", name: "index_gin_trgm_communication_channels_path", using: :gin, algorithm: :concurrently
add_index :pseudonyms, "lower(unique_id) #{schema}.gin_trgm_ops", name: "index_gin_trgm_pseudonyms_unique_id", using: :gin, algorithm: :concurrently

remove_index :users, name: "index_trgm_users_name"
remove_index :pseudonyms, name: "index_trgm_pseudonyms_sis_user_id"
remove_index :communication_channels, name: "index_trgm_communication_channels_path"
remove_index :pseudonyms, name: "index_trgm_pseudonyms_unique_id"
end
end

def down
if (schema = connection.extension_installed?(:pg_trgm))
add_index :users, "lower(name) #{schema}.gist_trgm_ops", name: "index_trgm_users_name", using: :gist, algorithm: :concurrently
add_index :pseudonyms, "lower(sis_user_id) #{schema}.gist_trgm_ops", name: "index_trgm_pseudonyms_sis_user_id", using: :gist, algorithm: :concurrently
add_index :communication_channels, "lower(path) #{schema}.gist_trgm_ops", name: "index_trgm_communication_channels_path", using: :gist, algorithm: :concurrently
add_index :pseudonyms, "lower(unique_id) #{schema}.gist_trgm_ops", name: "index_trgm_pseudonyms_unique_id", using: :gist, algorithm: :concurrently

remove_index :users, name: "index_gin_trgm_users_name"
remove_index :pseudonyms, name: "index_gin_trgm_pseudonyms_sis_user_id"
remove_index :communication_channels, name: "index_gin_trgm_communication_channels_path"
remove_index :pseudonyms, name: "index_gin_trgm_pseudonyms_unique_id"
end
end
end

0 comments on commit ee9ad6c

Please sign in to comment.