How can I use searchkick with pgSQL schemas / apartment and loop through schemas?
I am currently trying to use searchkick in my multi-user Rails 4 application that uses Apartment and pgSQL schemas to handle leases. However, I cannot find the searchkick to work. I'm not really sure what I'm doing wrong, but I think it might be that when I reindex it only gets reindexed on one schema.
I think I need to iterate over each schema, but I'm not sure how to do this in Apartment. They seem to do it automatically for the migration, but I'm trying to get it to work with searchkick. I want to edit the following rake command from searchkick to do this:
require 'rake'
namespace :searchkick do
task :reindex => :environment do
if ENV["CLASS"]
klass = ENV["CLASS"].constantize rescue nil
if klass
klass.reindex
else
abort "Could not find class: #{ENV["CLASS"]}"
end
else
abort "USAGE: rake searchkick:reindex CLASS=Product"
end
end
end
Please let me know if you have any suggestions
+3
source to share
1 answer
I was able to figure it out. I had to do the following and add the "Apartment" task here:
require 'rake'
require 'apartment/migrator'
namespace :searchkick do
task :reindex => :environment do
tenants.each do |tenant|
Apartment::Tenant.switch(tenant)
p 'switched'
if ENV["CLASS"]
klass = ENV["CLASS"].constantize rescue nil
if klass
klass.reindex
else
abort "Could not find class: #{ENV["CLASS"]}"
end
else
abort "USAGE: rake searchkick:reindex CLASS=Product"
end
end
end
end
0
source to share