active_tenant 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -18
- data/.travis.yml +5 -0
- data/Gemfile +4 -4
- data/LICENSE +21 -21
- data/README.md +41 -39
- data/Rakefile +2 -2
- data/active_tenant.gemspec +23 -23
- data/lib/active_tenant/active_record_extensions.rb +59 -55
- data/lib/active_tenant/adapters/postgres_adapter.rb +72 -69
- data/lib/active_tenant/adapters/sqlite_adapter.rb +75 -71
- data/lib/active_tenant/base.rb +40 -40
- data/lib/active_tenant/configuration.rb +4 -4
- data/lib/active_tenant/engine.rb +3 -3
- data/lib/active_tenant/version.rb +3 -3
- data/lib/active_tenant.rb +29 -29
- data/lib/tasks/migration.rake +21 -21
- data/spec/adapters_spec.rb +249 -217
- data/spec/migrations/20120823132512_create_globals.rb +10 -10
- data/spec/migrations/20120823132854_create_tenants.rb +12 -12
- data/spec/migrations/20120823132856_create_other_tenants.rb +12 -12
- data/spec/migrations/20120823132902_create_customs.rb +12 -12
- data/spec/models.rb +12 -0
- data/spec/spec_helper.rb +8 -10
- data/spec/support/adapter_test_helper.rb +69 -58
- metadata +40 -11
data/lib/active_tenant/base.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
module ActiveTenant
|
2
|
-
class Base
|
3
|
-
ADAPTERS = {
|
4
|
-
sqlite3: SQLiteAdapter,
|
5
|
-
postgresql: PostgresAdapter
|
6
|
-
}
|
7
|
-
|
8
|
-
delegate :all, :create, :remove, :with, :name, :global, :global?, to: :adapter
|
9
|
-
|
10
|
-
def migrate(name, version=nil)
|
11
|
-
::ActiveRecord::Base.logger.info "[ActiveTenant] Migrating tenant: #{name}"
|
12
|
-
with name do
|
13
|
-
::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
|
14
|
-
[:all, ::ActiveRecord::Base.tenant_name.to_sym].include? migration_proxy.send(:migration).class.tenant
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def migrate_all(version=nil)
|
20
|
-
all.each do |tenant|
|
21
|
-
migrate tenant, version
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def migrate_global(version=nil)
|
26
|
-
::ActiveRecord::Base.logger.info '[ActiveTenant] Migrating global db'
|
27
|
-
with global do
|
28
|
-
::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
|
29
|
-
migration_proxy.send(:migration).class.tenant.nil?
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def adapter
|
37
|
-
@adapter ||= ADAPTERS[::ActiveRecord::Base.connection_config[:adapter].to_sym].new
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
1
|
+
module ActiveTenant
|
2
|
+
class Base
|
3
|
+
ADAPTERS = {
|
4
|
+
sqlite3: SQLiteAdapter,
|
5
|
+
postgresql: PostgresAdapter
|
6
|
+
}
|
7
|
+
|
8
|
+
delegate :all, :create, :remove, :with, :connection_settings, :name, :global, :global?, to: :adapter
|
9
|
+
|
10
|
+
def migrate(name, version=nil)
|
11
|
+
::ActiveRecord::Base.logger.info "[ActiveTenant] Migrating tenant: #{name}"
|
12
|
+
with name do
|
13
|
+
::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
|
14
|
+
[:all, ::ActiveRecord::Base.tenant_name.to_sym].include? migration_proxy.send(:migration).class.tenant
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def migrate_all(version=nil)
|
20
|
+
all.each do |tenant|
|
21
|
+
migrate tenant, version
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def migrate_global(version=nil)
|
26
|
+
::ActiveRecord::Base.logger.info '[ActiveTenant] Migrating global db'
|
27
|
+
with global do
|
28
|
+
::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path, version) do |migration_proxy|
|
29
|
+
migration_proxy.send(:migration).class.tenant.nil?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def adapter
|
37
|
+
@adapter ||= ADAPTERS[::ActiveRecord::Base.connection_config[:adapter].to_sym].new
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
41
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module ActiveTenant
|
2
|
-
class Configuration
|
3
|
-
attr_accessor :global
|
4
|
-
end
|
1
|
+
module ActiveTenant
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :global
|
4
|
+
end
|
5
5
|
end
|
data/lib/active_tenant/engine.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module ActiveTenant
|
2
|
-
class Engine < ::Rails::Engine
|
3
|
-
end
|
1
|
+
module ActiveTenant
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
end
|
4
4
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module ActiveTenant
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
1
|
+
module ActiveTenant
|
2
|
+
VERSION = '0.0.3'
|
3
|
+
end
|
data/lib/active_tenant.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'rails'
|
2
|
-
require 'active_record'
|
3
|
-
|
4
|
-
require 'active_tenant/version'
|
5
|
-
require 'active_tenant/engine'
|
6
|
-
require 'active_tenant/adapters/sqlite_adapter'
|
7
|
-
require 'active_tenant/adapters/postgres_adapter'
|
8
|
-
require 'active_tenant/base'
|
9
|
-
require 'active_tenant/active_record_extensions'
|
10
|
-
require 'active_tenant/configuration'
|
11
|
-
|
12
|
-
module ActiveTenant
|
13
|
-
|
14
|
-
def self.configuration
|
15
|
-
@@configuration ||= Configuration.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.configure
|
19
|
-
yield(configuration)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.current
|
23
|
-
ActiveTenant::Base.new
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
ActiveRecord::Base.send :extend, ActiveTenant::ActiveRecord::Base
|
29
|
-
ActiveRecord::Migration.send :extend, ActiveTenant::ActiveRecord::Migration
|
1
|
+
require 'rails'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
require 'active_tenant/version'
|
5
|
+
require 'active_tenant/engine'
|
6
|
+
require 'active_tenant/adapters/sqlite_adapter'
|
7
|
+
require 'active_tenant/adapters/postgres_adapter'
|
8
|
+
require 'active_tenant/base'
|
9
|
+
require 'active_tenant/active_record_extensions'
|
10
|
+
require 'active_tenant/configuration'
|
11
|
+
|
12
|
+
module ActiveTenant
|
13
|
+
|
14
|
+
def self.configuration
|
15
|
+
@@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.current
|
23
|
+
ActiveTenant::Base.new
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
ActiveRecord::Base.send :extend, ActiveTenant::ActiveRecord::Base
|
29
|
+
ActiveRecord::Migration.send :extend, ActiveTenant::ActiveRecord::Migration
|
data/lib/tasks/migration.rake
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
namespace :db do
|
2
|
-
namespace :migrate do
|
3
|
-
|
4
|
-
desc 'Migrate global db and all tenants'
|
5
|
-
task :all => :environment do
|
6
|
-
ActiveTenant.current.migrate_global
|
7
|
-
ActiveTenant.current.migrate_all
|
8
|
-
end
|
9
|
-
|
10
|
-
desc 'Migrate only global db'
|
11
|
-
task :global => :environment do
|
12
|
-
ActiveTenant.current.migrate_global
|
13
|
-
end
|
14
|
-
|
15
|
-
desc 'Migrate all tenants excluding global db'
|
16
|
-
task :tenants => :environment do
|
17
|
-
ActiveTenant.current.migrate_all
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
1
|
+
namespace :db do
|
2
|
+
namespace :migrate do
|
3
|
+
|
4
|
+
desc 'Migrate global db and all tenants'
|
5
|
+
task :all => :environment do
|
6
|
+
ActiveTenant.current.migrate_global
|
7
|
+
ActiveTenant.current.migrate_all
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Migrate only global db'
|
11
|
+
task :global => :environment do
|
12
|
+
ActiveTenant.current.migrate_global
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Migrate all tenants excluding global db'
|
16
|
+
task :tenants => :environment do
|
17
|
+
ActiveTenant.current.migrate_all
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|