2025-06-09 09:55:30 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class AddNgramToSearchIndex < ActiveRecord::Migration[8.0]
|
|
|
|
|
def change
|
2025-06-11 18:50:01 +03:00
|
|
|
return unless adapter_name == 'PostgreSQL'
|
|
|
|
|
|
2025-07-30 18:45:28 +03:00
|
|
|
btree_gin_enabled = extension_enabled?('btree_gin')
|
|
|
|
|
|
2025-06-09 09:55:30 +03:00
|
|
|
add_column :search_entries, :ngram, :tsvector
|
|
|
|
|
|
2025-07-30 18:45:28 +03:00
|
|
|
add_index :search_entries, btree_gin_enabled ? %i[account_id tsvector] : :tsvector,
|
|
|
|
|
using: :gin, where: "record_type = 'Submitter'",
|
|
|
|
|
name: 'index_search_entries_on_account_id_ngram_submitter'
|
|
|
|
|
add_index :search_entries, btree_gin_enabled ? %i[account_id tsvector] : :tsvector,
|
|
|
|
|
using: :gin, where: "record_type = 'Submission'",
|
|
|
|
|
name: 'index_search_entries_on_account_id_ngram_submission'
|
|
|
|
|
add_index :search_entries, btree_gin_enabled ? %i[account_id tsvector] : :tsvector,
|
|
|
|
|
using: :gin, where: "record_type = 'Template'",
|
|
|
|
|
name: 'index_search_entries_on_account_id_ngram_template'
|
2025-06-09 09:55:30 +03:00
|
|
|
end
|
|
|
|
|
end
|