|
|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class CreateSearchEnties < ActiveRecord::Migration[8.0]
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
|
|
def up
|
|
|
|
|
return unless adapter_name == 'PostgreSQL'
|
|
|
|
|
|
|
|
|
|
enable_extension 'btree_gin'
|
|
|
|
|
|
|
|
|
|
create_table :search_entries do |t|
|
|
|
|
|
t.references :record, null: false, polymorphic: true, index: false
|
|
|
|
|
t.bigint :account_id, null: false
|
|
|
|
|
@ -14,12 +14,24 @@ class CreateSearchEnties < ActiveRecord::Migration[8.0]
|
|
|
|
|
t.timestamps
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
add_index :search_entries, %i[account_id tsvector], using: :gin, where: "record_type = 'Submitter'",
|
|
|
|
|
name: 'index_search_entries_on_account_id_tsvector_submitter'
|
|
|
|
|
add_index :search_entries, %i[account_id tsvector], using: :gin, where: "record_type = 'Submission'",
|
|
|
|
|
name: 'index_search_entries_on_account_id_tsvector_submission'
|
|
|
|
|
add_index :search_entries, %i[account_id tsvector], using: :gin, where: "record_type = 'Template'",
|
|
|
|
|
name: 'index_search_entries_on_account_id_tsvector_template'
|
|
|
|
|
begin
|
|
|
|
|
enable_extension 'btree_gin'
|
|
|
|
|
rescue StandardError
|
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
btree_gin_enabled = extension_enabled?('btree_gin')
|
|
|
|
|
|
|
|
|
|
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_tsvector_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_tsvector_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_tsvector_template'
|
|
|
|
|
|
|
|
|
|
add_index :search_entries, %i[record_id record_type], unique: true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -28,6 +40,10 @@ class CreateSearchEnties < ActiveRecord::Migration[8.0]
|
|
|
|
|
|
|
|
|
|
drop_table :search_entries
|
|
|
|
|
|
|
|
|
|
disable_extension 'btree_gin'
|
|
|
|
|
begin
|
|
|
|
|
disable_extension 'btree_gin'
|
|
|
|
|
rescue StandardError
|
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|