apartment 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5edda0f57e98bfa6166bb6bd4fcea9368cdc2963
4
- data.tar.gz: 8fdda9e1bbee41a48490ae0c61dc6bc18d5084c4
3
+ metadata.gz: caa901bdacc4fbec1f520ec03a1571b4fed1c087
4
+ data.tar.gz: 8c794d406def5147e36c94ee8f627178b84448fa
5
5
  SHA512:
6
- metadata.gz: 7450954792e78f6bd27bb8c4a6414853331562554d027cb54703746f59f1f255d898b8966349640494c7574917924ab3faa690ef07d295791d50693c56b6a0eb
7
- data.tar.gz: 9ffd46752338eb87341c0deb314395e0f8223beb5744a2ade9a632be6234f6ec68184a1ab01744b404978e11b25f80d03314645510cda7fb8875a1f86809c86d
6
+ metadata.gz: d75822a0b53d5d283f4c0989068f3528f0b5c27cd06b9c7ff3b56ceb5d8659e504229445ec73ef01300e14bf7b7d8eae61dcfc7c34d9e66b4f4dd921dedf1502
7
+ data.tar.gz: 42b087cc0ee285e1da347bd72b3949e491215b1f268f3a88131b353eeb127020ba1295d16f3beaeceb4bbec9ed55db7fc0cd60386a5767f7e6e3c51dc4bf9996
data/Appraisals CHANGED
@@ -1,5 +1,6 @@
1
1
  appraise "rails-3-2" do
2
2
  gem "rails", "~> 3.2"
3
+ gem "test-unit", "~> 3.0"
3
4
  end
4
5
 
5
6
  appraise "rails-4-0" do
@@ -13,3 +14,7 @@ end
13
14
  appraise "rails-4-2" do
14
15
  gem "rails", "~> 4.2"
15
16
  end
17
+
18
+ appraise "rails-5-0" do
19
+ gem "rails", "~> 5.0"
20
+ end
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
@@ -434,6 +434,7 @@ values being a hash with the database configuration to use.
434
434
  Example:
435
435
 
436
436
  ```ruby
437
+ config.with_multi_server_setup = true
437
438
  config.tenant_names = {
438
439
  'tenant1' => {
439
440
  adapter: 'postgresql',
@@ -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', '< 5.0'
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'
@@ -2,12 +2,12 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 3.2"
5
+ gem "rails", "~> 3.2.0"
6
+ gem "test-unit", "~> 3.0"
6
7
 
7
8
  group :local do
8
9
  gem "pry"
10
+ gem "guard-rspec", "~> 4.2"
9
11
  end
10
12
 
11
13
  gemspec :path => "../"
12
-
13
- gem "test-unit"
@@ -2,10 +2,11 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.0"
5
+ gem "rails", "~> 4.0.0"
6
6
 
7
7
  group :local do
8
8
  gem "pry"
9
+ gem "guard-rspec", "~> 4.2"
9
10
  end
10
11
 
11
12
  gemspec :path => "../"
@@ -2,10 +2,11 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.1"
5
+ gem "rails", "~> 4.1.0"
6
6
 
7
7
  group :local do
8
8
  gem "pry"
9
+ gem "guard-rspec", "~> 4.2"
9
10
  end
10
11
 
11
12
  gemspec :path => "../"
@@ -2,10 +2,11 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.2"
5
+ gem "rails", "~> 4.2.0"
6
6
 
7
7
  group :local do
8
8
  gem "pry"
9
+ gem "guard-rspec", "~> 4.2"
9
10
  end
10
11
 
11
12
  gemspec :path => "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.0"
6
+
7
+ group :local do
8
+ gem "pry"
9
+ gem "guard-rspec", "~> 4.2"
10
+ end
11
+
12
+ gemspec :path => "../"
@@ -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
- create_tenant(tenant)
23
+ run_callbacks :create do
24
+ create_tenant(tenant)
21
25
 
22
- switch(tenant) do
23
- import_database_schema
26
+ switch(tenant) do
27
+ import_database_schema
24
28
 
25
- # Seed data if appropriate
26
- seed_data if Apartment.seed_after_create
29
+ # Seed data if appropriate
30
+ seed_data if Apartment.seed_after_create
27
31
 
28
- yield if block_given?
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
- return reset if tenant.nil?
88
+ run_callbacks :switch do
89
+ return reset if tenant.nil?
84
90
 
85
- connect_to_new(tenant).tap do
86
- Apartment.connection.clear_query_cache
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
- # neutral connection is necessary whenever you need to create/remove a database from a server.
259
- # example: when you use postgresql, you need to connect to the default postgresql database before you create your own.
260
- def with_neutral_connection(tenant, &block)
261
- SeparateDbConnectionHandler.establish_connection(multi_tenantify(tenant, false))
262
- yield(SeparateDbConnectionHandler.connection)
263
- SeparateDbConnectionHandler.connection.close
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
@@ -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 "Apartment::Reloader"
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
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Apartment
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -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
@@ -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.1.0
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-05-26 00:00:00.000000000 Z
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: '5.0'
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: '5.0'
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