point index_trgm_users_name_active_only at the right column

fixes CNVS-30740

Change-Id: I2463a0add13cead70f89524132b6b6eac640e945
Reviewed-on: https://gerrit.instructure.com/86769
Reviewed-by: Cody Cutrer <cody@instructure.com>
Product-Review: Alex Boyd <aboyd@instructure.com>
QA-Review: Alex Boyd <aboyd@instructure.com>
Tested-by: Jenkins
This commit is contained in:
Alex Boyd 2016-08-02 20:42:00 -06:00
parent 5a975d407f
commit 697a1c4562
2 changed files with 27 additions and 3 deletions

View File

@ -1,17 +1,19 @@
class AddUserActiveOnlyGistIndexes < ActiveRecord::Migration
disable_ddl_transaction!
tag :predeploy
tag :postdeploy
def self.up
if schema = connection.extension_installed?(:pg_trgm)
concurrently = " CONCURRENTLY" if connection.open_transactions == 0
execute("CREATE INDEX#{concurrently} index_trgm_users_name_active_only ON #{User.quoted_table_name} USING gist(LOWER(short_name) #{schema}.gist_trgm_ops) WHERE workflow_state IN ('registered', 'pre_registered')")
# next line indexes the wrong column, so it's nuked and another migration adds the right one and fixes up
# people who already ran this migration
# execute("CREATE INDEX#{concurrently} index_trgm_users_name_active_only ON #{User.quoted_table_name} USING gist(LOWER(short_name) #{schema}.gist_trgm_ops) WHERE workflow_state IN ('registered', 'pre_registered')")
execute("CREATE INDEX#{concurrently} index_trgm_users_short_name_active_only ON #{User.quoted_table_name} USING gist(LOWER(short_name) #{schema}.gist_trgm_ops) WHERE workflow_state IN ('registered', 'pre_registered')")
end
end
def self.down
remove_index :users, name: 'index_trgm_users_name_active_only'
remove_index :users, name: 'index_trgm_users_name_active_only' if index_exists?(:users, 'index_trgm_users_name_active_only')
remove_index :users, name: 'index_trgm_users_short_name_active_only'
end
end

View File

@ -0,0 +1,22 @@
class FixUserActiveOnlyGistIndexes < ActiveRecord::Migration
disable_ddl_transaction!
tag :postdeploy
def self.up
if schema = connection.extension_installed?(:pg_trgm)
remove_index :users, name: 'index_trgm_users_name_active_only' if index_exists?(:users, 'index_trgm_users_name_active_only')
concurrently = " CONCURRENTLY" if connection.open_transactions == 0
execute("CREATE INDEX#{concurrently} index_trgm_users_name_active_only ON #{User.quoted_table_name} USING gist(LOWER(name) #{schema}.gist_trgm_ops) WHERE workflow_state IN ('registered', 'pre_registered')")
end
end
def self.down
if schema = connection.extension_installed?(:pg_trgm)
remove_index :users, name: 'index_trgm_users_name_active_only' if index_exists?(:users, 'index_trgm_users_name_active_only')
concurrently = " CONCURRENTLY" if connection.open_transactions == 0
execute("CREATE INDEX#{concurrently} index_trgm_users_name_active_only ON #{User.quoted_table_name} USING gist(LOWER(short_name) #{schema}.gist_trgm_ops) WHERE workflow_state IN ('registered', 'pre_registered')")
end
end
end