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 Method Summary collapse

Methods inherited from PostgresqlSchemaAdapter

#current_tenant, #drop, #initialize, #process_excluded_models, #reset

Methods inherited from AbstractAdapter

#create, #current, #current_database, #current_tenant, #drop, #initialize, #process, #process_excluded_models, #reset, #seed_data, #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



49
50
51
52
53
54
55
56
57
58
# File 'lib/apartment/adapters/jdbc_postgresql_adapter.rb', line 49

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 = tenant.to_s
  Apartment.connection.schema_search_path = full_search_path

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