Class: Apartment::Adapters::JDBCPostgresqlSchemaAdapter

Inherits:
PostgresqlSchemaAdapter show all
Defined in:
lib/apartment/adapters/jdbc_postgresql_adapter.rb

Overview

Separate Adapter for Postgresql when using schemas

Instance Attribute Summary

Attributes inherited from AbstractAdapter

#default_tenant

Instance Method Summary collapse

Methods inherited from PostgresqlSchemaAdapter

#current, #initialize, #reset

Methods inherited from AbstractAdapter

#create, #current, #drop, #each, #environmentify, #initialize, #process_excluded_models, #reset, #seed_data, #switch, #switch!

Constructor Details

This class inherits a constructor from Apartment::Adapters::PostgresqlSchemaAdapter

Instance Method Details

#connect_to_new(tenant = nil) ⇒ Object

Set schema search path to new schema



38
39
40
41
42
43
44
45
46
47
# File 'lib/apartment/adapters/jdbc_postgresql_adapter.rb', line 38

def connect_to_new(tenant = nil)
  return reset if tenant.nil?
  raise ActiveRecord::StatementInvalid.new("Could not find schema #{tenant}") unless Apartment.connection.all_schemas.include? tenant.to_s

  @current = tenant.to_s
  Apartment.connection.schema_search_path = full_search_path

rescue ActiveRecord::StatementInvalid, ActiveRecord::JDBCError
  raise TenantNotFound, "One of the following schema(s) is invalid: #{full_search_path}"
end