0

i am getting error when execute Apartment::Tenant.switch!("tenant_name") even when the tenant were exists.

When i run Apartment::tenant_names,it return an array contain ["murah5","rahmatullah","test"] then i run Apartment::Tenant.switch!("murah5") it return :

Apartment::TenantNotFound: One of the following schema(s) is invalid: "murah5" "public" from /Users/fourtyonestudio/.rvm/gems/ruby-2.4.1/gems/apartment-1.2.0/lib/apartment/adapters/postgresql_adapter.rb:72:inrescue in connect_to_new'`

can you help me with this case ?

2 Answers2

1

This error may be due to the missing schema in the database for that name

https://dba.stackexchange.com/questions/40045/how-do-i-list-all-schemas-in-postgresql

Ram on Rails
  • 1,299
  • 11
  • 25
0

you can make a method in the model (which creates the tenants)

     class Tenant < ApplicationRecord
       def self.switch(subdomain)
         Apartment::Tenant.switch! subdomain
       end
     end

then you can switch your subdomain from rails console like

  Tenant.switch('app')

check you current subdomain by Apartment::Tenant.current

Manav
  • 561
  • 3
  • 10
  • 20