canvas-lms/db/migrate/20131106171153_add_more_gis...

22 lines
1.1 KiB
Ruby

class AddMoreGistIndexes < ActiveRecord::Migration
disable_ddl_transaction!
tag :predeploy
def self.up
if is_postgres? && (schema = connection.extension_installed?(:pg_trgm))
concurrently = " CONCURRENTLY" if connection.open_transactions == 0
execute("CREATE INDEX#{concurrently} index_trgm_users_short_name ON users USING gist(LOWER(short_name) #{schema}.gist_trgm_ops)")
execute("CREATE INDEX#{concurrently} index_trgm_courses_name ON courses USING gist(LOWER(name) #{schema}.gist_trgm_ops)")
execute("CREATE INDEX#{concurrently} index_trgm_courses_course_code ON courses USING gist(LOWER(course_code) #{schema}.gist_trgm_ops)")
execute("CREATE INDEX#{concurrently} index_trgm_courses_sis_source_id ON courses USING gist(LOWER(sis_source_id) #{schema}.gist_trgm_ops)")
end
end
def self.down
remove_index :users, name: 'index_trgm_users_short_name'
remove_index :courses, name: 'index_trgm_courses_name'
remove_index :courses, name: 'index_trgm_courses_course_code'
remove_index :courses, name: 'index_trgm_courses_sis_source_id'
end
end