Module: PandaPal::OrganizationConcerns::TenantHandling

Extended by:
ActiveSupport::Concern
Included in:
PandaPal::Organization
Defined in:
app/models/panda_pal/organization_concerns/tenant_handling.rb

Instance Method Summary collapse

Instance Method Details

#rename!(new_name) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'app/models/panda_pal/organization_concerns/tenant_handling.rb', line 33

def rename!(new_name)
  do_switch = Apartment::Tenant.current == name
  ActiveRecord::Base.connection.execute(
    "ALTER SCHEMA \"#{name}\" RENAME TO \"#{new_name}\";"
  )
  self.class.where(id: id).update_all(name: new_name)
  reload
  switch_tenant if do_switch
end

#switch_tenant(&block) ⇒ Object



25
26
27
28
29
30
31
# File 'app/models/panda_pal/organization_concerns/tenant_handling.rb', line 25

def switch_tenant(&block)
  if block_given?
    Apartment::Tenant.switch(tenant_name, &block)
  else
    Apartment::Tenant.switch!(tenant_name)
  end
end

#tenant_nameObject



21
22
23
# File 'app/models/panda_pal/organization_concerns/tenant_handling.rb', line 21

def tenant_name
  name
end