apartment 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Appraisals +5 -0
- data/HISTORY.md +12 -1
- data/README.md +1 -0
- data/apartment.gemspec +1 -1
- data/gemfiles/rails_3_2.gemfile +3 -3
- data/gemfiles/rails_4_0.gemfile +2 -1
- data/gemfiles/rails_4_1.gemfile +2 -1
- data/gemfiles/rails_4_2.gemfile +2 -1
- data/gemfiles/rails_5_0.gemfile +12 -0
- data/lib/apartment.rb +1 -1
- data/lib/apartment/adapters/abstract_adapter.rb +29 -18
- data/lib/apartment/adapters/postgresql_adapter.rb +1 -1
- data/lib/apartment/railtie.rb +1 -1
- data/lib/apartment/tenant.rb +1 -1
- data/lib/apartment/version.rb +1 -1
- data/spec/examples/generic_adapter_custom_configuration_example.rb +5 -0
- data/spec/support/apartment_helpers.rb +0 -6
- data/spec/support/setup.rb +1 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caa901bdacc4fbec1f520ec03a1571b4fed1c087
|
4
|
+
data.tar.gz: 8c794d406def5147e36c94ee8f627178b84448fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d75822a0b53d5d283f4c0989068f3528f0b5c27cd06b9c7ff3b56ceb5d8659e504229445ec73ef01300e14bf7b7d8eae61dcfc7c34d9e66b4f4dd921dedf1502
|
7
|
+
data.tar.gz: 42b087cc0ee285e1da347bd72b3949e491215b1f268f3a88131b353eeb127020ba1295d16f3beaeceb4bbec9ed55db7fc0cd60386a5767f7e6e3c51dc4bf9996
|
data/Appraisals
CHANGED
data/HISTORY.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# 1.2.0
|
2
|
+
* July 28, 2016
|
3
|
+
|
4
|
+
- Official Rails 5 support
|
5
|
+
|
6
|
+
# 1.1.0
|
7
|
+
* May 26, 2016
|
8
|
+
|
9
|
+
- Reset tenant after each request
|
10
|
+
- [Support callbacks](https://github.com/influitive/apartment/commit/ff9c9d092a781026502f5997c0bbedcb5748bc83) on switch [cbeer]
|
11
|
+
- Preliminary support for [separate database hosts](https://github.com/influitive/apartment/commit/abdffbf8cd9fba87243f16c86390da13e318ee1f) [apneadiving]
|
12
|
+
|
1
13
|
# 1.0.2
|
2
14
|
* July 2, 2015
|
3
15
|
|
@@ -323,4 +335,3 @@
|
|
323
335
|
* March 30, 2011 *
|
324
336
|
|
325
337
|
- Original pass from Ryan
|
326
|
-
|
data/README.md
CHANGED
data/apartment.gemspec
CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
MSG
|
36
36
|
|
37
37
|
# must be >= 3.1.2 due to bug in prepared_statements
|
38
|
-
s.add_dependency 'activerecord', '>= 3.1.2', '<
|
38
|
+
s.add_dependency 'activerecord', '>= 3.1.2', '< 6.0'
|
39
39
|
s.add_dependency 'rack', '>= 1.3.6'
|
40
40
|
|
41
41
|
s.add_development_dependency 'appraisal'
|
data/gemfiles/rails_3_2.gemfile
CHANGED
data/gemfiles/rails_4_0.gemfile
CHANGED
data/gemfiles/rails_4_1.gemfile
CHANGED
data/gemfiles/rails_4_2.gemfile
CHANGED
data/lib/apartment.rb
CHANGED
@@ -11,7 +11,7 @@ module Apartment
|
|
11
11
|
|
12
12
|
extend Forwardable
|
13
13
|
|
14
|
-
ACCESSOR_METHODS = [:use_schemas, :use_sql, :seed_after_create, :prepend_environment, :append_environment]
|
14
|
+
ACCESSOR_METHODS = [:use_schemas, :use_sql, :seed_after_create, :prepend_environment, :append_environment, :with_multi_server_setup ]
|
15
15
|
WRITER_METHODS = [:tenant_names, :database_schema_file, :excluded_models, :default_schema, :persistent_schemas, :connection_class, :tld_length, :db_migrate_tenants, :seed_data_file]
|
16
16
|
|
17
17
|
attr_accessor(*ACCESSOR_METHODS)
|
@@ -3,6 +3,9 @@ require 'apartment/deprecation'
|
|
3
3
|
module Apartment
|
4
4
|
module Adapters
|
5
5
|
class AbstractAdapter
|
6
|
+
include ActiveSupport::Callbacks
|
7
|
+
define_callbacks :create, :switch
|
8
|
+
|
6
9
|
attr_writer :default_tenant
|
7
10
|
|
8
11
|
# @constructor
|
@@ -17,15 +20,17 @@ module Apartment
|
|
17
20
|
# @param {String} tenant Tenant name
|
18
21
|
#
|
19
22
|
def create(tenant)
|
20
|
-
|
23
|
+
run_callbacks :create do
|
24
|
+
create_tenant(tenant)
|
21
25
|
|
22
|
-
|
23
|
-
|
26
|
+
switch(tenant) do
|
27
|
+
import_database_schema
|
24
28
|
|
25
|
-
|
26
|
-
|
29
|
+
# Seed data if appropriate
|
30
|
+
seed_data if Apartment.seed_after_create
|
27
31
|
|
28
|
-
|
32
|
+
yield if block_given?
|
33
|
+
end
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
@@ -80,10 +85,12 @@ module Apartment
|
|
80
85
|
# @param {String} tenant name
|
81
86
|
#
|
82
87
|
def switch!(tenant = nil)
|
83
|
-
|
88
|
+
run_callbacks :switch do
|
89
|
+
return reset if tenant.nil?
|
84
90
|
|
85
|
-
|
86
|
-
|
91
|
+
connect_to_new(tenant).tap do
|
92
|
+
Apartment.connection.clear_query_cache
|
93
|
+
end
|
87
94
|
end
|
88
95
|
end
|
89
96
|
|
@@ -155,9 +162,6 @@ module Apartment
|
|
155
162
|
conn.execute("DROP DATABASE #{environmentify(tenant)}")
|
156
163
|
end
|
157
164
|
|
158
|
-
class SeparateDbConnectionHandler < ::ActiveRecord::Base
|
159
|
-
end
|
160
|
-
|
161
165
|
# Create the tenant
|
162
166
|
#
|
163
167
|
# @param {String} tenant Database name
|
@@ -255,12 +259,16 @@ module Apartment
|
|
255
259
|
Apartment.db_config_for(tenant).clone
|
256
260
|
end
|
257
261
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
262
|
+
def with_neutral_connection(tenant, &block)
|
263
|
+
if Apartment.with_multi_server_setup
|
264
|
+
# neutral connection is necessary whenever you need to create/remove a database from a server.
|
265
|
+
# example: when you use postgresql, you need to connect to the default postgresql database before you create your own.
|
266
|
+
SeparateDbConnectionHandler.establish_connection(multi_tenantify(tenant, false))
|
267
|
+
yield(SeparateDbConnectionHandler.connection)
|
268
|
+
SeparateDbConnectionHandler.connection.close
|
269
|
+
else
|
270
|
+
yield(Apartment.connection)
|
271
|
+
end
|
264
272
|
end
|
265
273
|
|
266
274
|
def reset_on_connection_exception?
|
@@ -278,6 +286,9 @@ module Apartment
|
|
278
286
|
def raise_connect_error!(tenant, exception)
|
279
287
|
raise TenantNotFound, "Error while connecting to tenant #{environmentify(tenant)}: #{ exception.message }"
|
280
288
|
end
|
289
|
+
|
290
|
+
class SeparateDbConnectionHandler < ::ActiveRecord::Base
|
291
|
+
end
|
281
292
|
end
|
282
293
|
end
|
283
294
|
end
|
@@ -140,7 +140,7 @@ module Apartment
|
|
140
140
|
# @return {String} raw SQL contaning inserts with data from schema_migrations
|
141
141
|
#
|
142
142
|
def pg_dump_schema_migrations_data
|
143
|
-
with_pg_env { `pg_dump -a --inserts -t schema_migrations -n #{default_tenant} #{dbname}` }
|
143
|
+
with_pg_env { `pg_dump -a --inserts -t schema_migrations -t ar_internal_metadata -n #{default_tenant} #{dbname}` }
|
144
144
|
end
|
145
145
|
|
146
146
|
# Temporary set Postgresql related environment variables if there are in @config
|
data/lib/apartment/railtie.rb
CHANGED
@@ -47,7 +47,7 @@ module Apartment
|
|
47
47
|
|
48
48
|
# Apartment::Reloader is middleware to initialize things properly on each request to dev
|
49
49
|
initializer 'apartment.init' do |app|
|
50
|
-
app.config.middleware.use
|
50
|
+
app.config.middleware.use Apartment::Reloader
|
51
51
|
end
|
52
52
|
|
53
53
|
# Overrides reload! to also call Apartment::Tenant.init as well so that the reloaded classes have the proper table_names
|
data/lib/apartment/tenant.rb
CHANGED
@@ -9,7 +9,7 @@ module Apartment
|
|
9
9
|
extend self
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
-
def_delegators :adapter, :create, :drop, :switch, :switch!, :current, :each, :reset, :seed, :current_tenant, :default_tenant
|
12
|
+
def_delegators :adapter, :create, :drop, :switch, :switch!, :current, :each, :reset, :set_callback, :seed, :current_tenant, :default_tenant
|
13
13
|
|
14
14
|
attr_writer :config
|
15
15
|
|
data/lib/apartment/version.rb
CHANGED
@@ -12,6 +12,11 @@ shared_examples_for "a generic apartment adapter able to handle custom configura
|
|
12
12
|
|
13
13
|
before do
|
14
14
|
Apartment.tenant_names = custom_tenant_names
|
15
|
+
Apartment.with_multi_server_setup = true
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Apartment.with_multi_server_setup = false
|
15
20
|
end
|
16
21
|
|
17
22
|
context "database key taken from specific config" do
|
@@ -15,12 +15,6 @@ module Apartment
|
|
15
15
|
"db%d" % @x += 1
|
16
16
|
end
|
17
17
|
|
18
|
-
def reset_table_names
|
19
|
-
Apartment.excluded_models.each do |model|
|
20
|
-
model.constantize.reset_table_name
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
18
|
def drop_schema(schema)
|
25
19
|
ActiveRecord::Base.connection.execute("DROP SCHEMA IF EXISTS #{schema} CASCADE") rescue true
|
26
20
|
end
|
data/spec/support/setup.rb
CHANGED
@@ -22,7 +22,6 @@ module Apartment
|
|
22
22
|
# before
|
23
23
|
Apartment::Tenant.reload!(config)
|
24
24
|
ActiveRecord::Base.establish_connection config
|
25
|
-
Apartment::Test.reset_table_names
|
26
25
|
|
27
26
|
example.run
|
28
27
|
|
@@ -35,8 +34,8 @@ module Apartment
|
|
35
34
|
|
36
35
|
Apartment.connection_class.remove_connection(klass)
|
37
36
|
klass.clear_all_connections!
|
37
|
+
klass.reset_table_name
|
38
38
|
end
|
39
|
-
Apartment::Test.reset_table_names
|
40
39
|
Apartment.reset
|
41
40
|
Apartment::Tenant.reload!
|
42
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apartment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brunner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
version: 3.1.2
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '
|
23
|
+
version: '6.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: 3.1.2
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '6.0'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: rack
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- gemfiles/rails_4_0.gemfile
|
185
185
|
- gemfiles/rails_4_1.gemfile
|
186
186
|
- gemfiles/rails_4_2.gemfile
|
187
|
+
- gemfiles/rails_5_0.gemfile
|
187
188
|
- lib/apartment.rb
|
188
189
|
- lib/apartment/adapters/abstract_adapter.rb
|
189
190
|
- lib/apartment/adapters/abstract_jdbc_adapter.rb
|