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, #default_tenant, #init, #initialize, #reset

Methods inherited from AbstractAdapter

#create, #current, #drop, #each, #environmentify, #init, #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



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

def connect_to_new(tenant = nil)
  return reset if tenant.nil?
  raise ActiveRecord::StatementInvalid, "Could not find schema #{tenant}" unless schema_exists?(tenant)

  @current = tenant.is_a?(Array) ? tenant.map(&:to_s) : 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