influitive / apartment

Database multi-tenancy for Rack (and Rails) applications
2.68k stars 460 forks source link

Switch from subdomains to generic elevator #652

Open mfts opened 4 years ago

mfts commented 4 years ago

I have set up an application with tenants based on subdomain. Here I used the subdomain elevators and subdomain middleware as instructed.

Now, I would like to change the way Apartment finds the database schema to a different variable because I would like to let my users change their subdomain.

Steps to reproduce

## apartment.rb

require 'apartment/elevators/generic'

Apartment.configure do |config|

  config.excluded_models = %w{ Tenant }

  config.tenant_names = lambda { Tenant.pluck :uuid }

  config.seed_after_create = true
end

Rails.application.config.middleware.use "Apartment::Elevators::Generic", lambda { |request|
  Tenant.find_by(subdomain: request.subdomains.first).uuid
}

Expected behavior

Apartment finds database by uuids

Actual behavior

Error with the following message

undefined method `new' for "Apartment::Elevators::Generic":String (NoMethodError)

I understand that I should somehow change the schema names initially to the uuids but still there seems to be something wrong.

System configuration

mfts commented 4 years ago

Referncing another issue #242 because I think they're related