Skip to content

Instantly share code, notes, and snippets.

@yurifrl
Forked from tiagoamaro/about.md
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurifrl/503aea197b699ef21247 to your computer and use it in GitHub Desktop.
Save yurifrl/503aea197b699ef21247 to your computer and use it in GitHub Desktop.
searchkick-apartment-example-codes
class Post
searchkick index_name: -> { [Apartment::Tenant.current, model_name.plural, Rails.env].join('_') }
end
class Post
include SchemaSearchable
searchkick index_name: tenant_index_name
end
module SchemaSearchable
extend ActiveSupport::Concern
module ClassMethods
def tenant_index_name
-> { [Apartment::Tenant.current, model_name.plural, Rails.env].join('_') }
end
end
end
namespace :searchkick do
desc 'Reindex all models on all tenants'
task reindex_tenants: :environment do
Rails.application.eager_load!
# You'll need to tell the rake task which tenant_names you are going to use
User.pluck(:database).each do |schema|
Apartment::Tenant.switch schema
(Searchkick::Reindex.instance_variable_get(:@descendents) || []).each do |model|
puts "Reindexing #{model.name} on #{schema}"
Apartment::Tenant.switch schema
model.reindex
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment