Closed Xosmond closed 2 years ago
@Xosmond
Would you please give us more information about your configurations like as follows.
Database: (Tell us what database and its version you use.)
Apartment version:
Apartment config:
use_schemas
: (true
or false
)Rails (or ActiveRecord) version:
Ruby version:
@meganemura Here is the information:
Postgresql 9.6.5
Gem: pg 0.21.0
apartment (2.0.0)
require 'apartment/elevators/first_subdomain'
require 'apartment/tenant'
module Apartment module Elevators class MyElevator < Apartment::Elevators::FirstSubdomain def call(env) request = Rack::Request.new(env) database = @processor.call(request) if database result = Apartment::Tenant.switch!(database) rescue "notfound" if result == "notfound" Rails.logger.error "Error: Apartment says tenant was not found for #{database.inspect}" raise ActionController::RoutingError.new('Not Found') else @app.call(env) end else @app.call(env) end end end end end
Apartment.configure do |config| config.excluded_models = %w{ Company TaxType Permission } config.tenant_names = lambda { Company.pluck :subdomain } end
Rails.application.config.middleware.use Apartment::Elevators::MyElevator
*Note: The custom elevator is just for manage the TenantNotFound Error, I got the same problem without the custom elevator.
- Rails:
rails (5.1.4) activerecord (5.1.4)
- Ruby: `ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin16]`
@Xosmond were you able to solve this I'm having the same problem
@acrogenesis As I said I had to manually change the table names on the before suite callback of rspec (depending of your tenant name for tests):
(ApplicationRecord.descendants - public_models).each do |model|
model.table_name = "test." + model.table_name unless /test.*/.match(model.table_name)
end
This also happens when not using an elevator at all. A random client db is used when not switching to a specific tenant. I don't know if this is fixable without elevator.
Closing due to no recent activity.
Hello, I have a problem with Apartment because I have found that table names are not correct sometimes on my tests:
This code generates mostly time:
But only sometimes:
I had to manually change them:
Any idea why sometimes this is happening?
PD: Complete code is on Stackoverflow question, I think I should delete that question.