module Apartment::Database

def self.postgresql_adapter(config)

def self.postgresql_adapter(config)
  Adapters::PostgresqlAdapter.new config, :schema_search_path => ActiveRecord::Base.connection.schema_search_path
end

def adapter

def adapter
@adapter ||= begin
  adapter_method = "#{config[:adapter]}_adapter"

  begin
      require "apartment/adapters/#{adapter_method}"
    rescue LoadError => e
      raise "The adapter `#{config[:adapter]}` is not yet supported"
    end
    unless respond_to?(adapter_method)
      raise AdapterNotFound, "database configuration specifies nonexistent #{config[:adapter]} adapter"
    end
  
    send(adapter_method, config)
  end
nd

def config

def config
  @config ||= Rails.configuration.database_configuration[Rails.env].symbolize_keys
end

def connect_exclusions

def connect_exclusions
  # Establish a connection for each specific excluded model
    # Thus all other models will shared a connection (at ActiveRecord::Base) and we can modify at will
   Apartment.excluded_models.each do |excluded_model|
		excluded_model.establish_connection config
	end
  end

def init

This must be done before creating any new schemas or switching
Call init to establish a connection to the public schema on all excluded models
def init
  connect_exclusions
 end

def reload!

def reload!
  @adapter = nil
  @config = nil
 end