Module: Apartment::SchemaCache

Defined in:
lib/apartment/schema_cache.rb

Class Method Summary collapse

Class Method Details

.cache_path_for(tenant) ⇒ Object



21
22
23
24
# File 'lib/apartment/schema_cache.rb', line 21

def cache_path_for(tenant)
  base = defined?(Rails) && Rails.root ? Rails.root.join('db') : Pathname.new('db')
  base.join("schema_cache_#{tenant}.yml").to_s
end

.dump(tenant) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/apartment/schema_cache.rb', line 9

def dump(tenant)
  path = cache_path_for(tenant)
  Apartment::Tenant.switch(tenant) do
    ActiveRecord::Base.connection.schema_cache.dump_to(path)
  end
  path
end

.dump_allObject



17
18
19
# File 'lib/apartment/schema_cache.rb', line 17

def dump_all
  Apartment.config.tenants_provider.call.map { |t| dump(t) }
end