I'm using rails-on-services/apartment this is a Multitenancy for Rails and ActiveRecord
my setup is every time I create a Tenant the gem automatically creates a specific schema for the new tenant.
every time I run the rails sunspot:reindex the record will not appear in the search level. but in ActiveRecord(ex.Client.all) the record is there.
my theory is the tenant I created is not reindexing. is there a way to reindex specific schema? or I'm missing something?
It appears that the problem is that when you run the rails
sunspot:reindexcommand, the data for each tenant's schema isn't being reindexed. To fix this, you can create a custom Rake task that loops through each tenant and reindexes the data for each schema separately.Follow these steps to create the Rake task:
Create a new file called
sunspot.rakein your Rails project'slib/tasksdirectory:This Rake task will iterate through all tenants, switch to the corresponding tenant's schema using
Apartment::Tenant.switch, and then call thesunspot:reindextask to reindex the data for that schema.To run the newly created Rake task, enter the following command:
This command will reindex the data for all tenants' schemas separately, ensuring that the data for each schema is indexed correctly.
Remember to replace
Tenantwith the appropriate model name that represents your tenant in your application.