Class: ActiveTenant::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_tenant/base.rb

Constant Summary collapse

ADAPTERS =
{
    sqlite3: SQLiteAdapter,
    postgresql: PostgresAdapter
}

Instance Method Summary collapse

Instance Method Details

#migrate(name, version = nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/active_tenant/base.rb', line 10

def migrate(name, version=nil)
  ::ActiveRecord::Base.logger.info "[ActiveTenant] Migrating tenant: #{name}"
  with name do
    ::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
      [:all, ::ActiveRecord::Base.tenant_name.to_sym].include? migration_proxy.send(:migration).class.tenant
    end
  end
end

#migrate_all(version = nil) ⇒ Object



19
20
21
22
23
# File 'lib/active_tenant/base.rb', line 19

def migrate_all(version=nil)
  all.each do |tenant|
    migrate tenant, version
  end
end

#migrate_global(version = nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/active_tenant/base.rb', line 25

def migrate_global(version=nil)
  ::ActiveRecord::Base.logger.info '[ActiveTenant] Migrating global db'
  with global do
    ::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
      migration_proxy.send(:migration).class.tenant.nil?
    end
  end
end