Class: Apartment::Adapters::PostgresqlAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/apartment/adapters/postgresql_adapter.rb

Instance Method Summary collapse

Methods inherited from AbstractAdapter

#connect_and_reset, #initialize, #switch

Constructor Details

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

Instance Method Details

#connect_to_new(database) ⇒ Object

Set schema path or connect to new db



15
16
17
18
19
20
21
# File 'lib/apartment/adapters/postgresql_adapter.rb', line 15

def connect_to_new(database)	      
 		return ActiveRecord::Base.connection.schema_search_path = database if using_schemas?

  super
   rescue ActiveRecord::StatementInvalid => e
     raise SchemaNotFound, e
end

#create(database) ⇒ Object



23
24
25
26
27
28
# File 'lib/apartment/adapters/postgresql_adapter.rb', line 23

def create(database)
			  reset
			  # Postgres will (optionally) use 'schemas' instead of actual dbs, create a new schema while connected to main (global) db
  create_schema(database) if using_schemas?
  super(database)
end

#resetObject



30
31
32
33
34
35
36
# File 'lib/apartment/adapters/postgresql_adapter.rb', line 30

def reset
if using_schemas?
	  ActiveRecord::Base.connection.schema_search_path = @defaults[:schema_search_path]
 else
   super
 end
end