20170317193015_add_search_index_to_accounts.rb 530 B

123456789101112131415161718192021
  1. # frozen_string_literal: true
  2. class AddSearchIndexToAccounts < ActiveRecord::Migration[5.0]
  3. def up
  4. execute <<~SQL.squish
  5. CREATE INDEX search_index
  6. ON accounts
  7. USING gin(
  8. (
  9. setweight(to_tsvector('simple', accounts.display_name), 'A') ||
  10. setweight(to_tsvector('simple', accounts.username), 'B') ||
  11. setweight(to_tsvector('simple', coalesce(accounts.domain, '')), 'C')
  12. )
  13. )
  14. SQL
  15. end
  16. def down
  17. remove_index :accounts, name: :search_index
  18. end
  19. end