ros-apartment 2.10.0 → 2.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9729bd0cd46375da3b48c1aad59bd2de396f90e9a7cd92d24dafee964988cbc4
4
- data.tar.gz: 1e0b6a955a15691edcbbb680657d1a65c75c7b49cd93e342d4df7212d29313c5
3
+ metadata.gz: 6182f5dcd4e369e6f497295705079b3d0b20d644d8006c5a256d8618eff1a2c3
4
+ data.tar.gz: 351be335f73230dd83df3020ba77b33f8e33e297f67c5256210f3e0c0c12e749
5
5
  SHA512:
6
- metadata.gz: 9f12f51635a20b87a5a8bddcd00eceac5ccd355699e2932947689a929695b1ad4337528da976a7905c31ed91413ee41eddc6f2ce7aed1d79f7643073b50053fa
7
- data.tar.gz: 617c702d5f698a3a8b81649f10bb91373ff9fabab4755270ffc2289a44ea7b48b814f939c4363bb23d45a378f1f444963188980ea0acc1e5b76cd7d28207e3f3
6
+ metadata.gz: 7714a5182a47cefc6a95d85118278263bf4d326c5441184005a3ef48cf10368cd123602a0e5635547233c12ecb587e107dc72c0a117423dd774054f19767e3ce
7
+ data.tar.gz: 6b4247215b4754d031ce248f6e457d1c509157d310964e74cc72f05e8f896215b29341cd892515c9e9803a2f0db6528f180474b0c14cf03384ee1ac4f9693164
data/.circleci/config.yml CHANGED
@@ -70,7 +70,9 @@ workflows:
70
70
  matrix:
71
71
  parameters:
72
72
  ruby_version: ["ruby:2.6-buster", "ruby:2.7-buster", "ruby:3.0-buster"]
73
- gemfile: ["gemfiles/rails_5_2.gemfile", "gemfiles/rails_6_0.gemfile", "gemfiles/rails_6_1.gemfile"]
73
+ gemfile: ["gemfiles/rails_5_2.gemfile", "gemfiles/rails_6_0.gemfile", "gemfiles/rails_6_1.gemfile", "gemfiles/rails_7_0.gemfile"]
74
74
  exclude:
75
75
  - ruby_version: "ruby:3.0-buster"
76
76
  gemfile: "gemfiles/rails_5_2.gemfile"
77
+ - ruby_version: "ruby:2.6-buster"
78
+ gemfile: "gemfiles/rails_7_0.gemfile"
data/.rubocop_todo.yml CHANGED
@@ -77,7 +77,6 @@ RSpec/DescribedClass:
77
77
  - 'spec/tenant_spec.rb'
78
78
  - 'spec/unit/elevators/host_hash_spec.rb'
79
79
  - 'spec/unit/migrator_spec.rb'
80
- - 'spec/unit/reloader_spec.rb'
81
80
 
82
81
  # Offense count: 5
83
82
  # Cop supports --auto-correct.
@@ -128,7 +127,6 @@ RSpec/FilePath:
128
127
  - 'spec/unit/elevators/host_spec.rb'
129
128
  - 'spec/unit/elevators/subdomain_spec.rb'
130
129
  - 'spec/unit/migrator_spec.rb'
131
- - 'spec/unit/reloader_spec.rb'
132
130
 
133
131
  # Offense count: 1
134
132
  # Cop supports --auto-correct.
@@ -159,7 +157,6 @@ RSpec/InstanceVariable:
159
157
  # Cop supports --auto-correct.
160
158
  RSpec/LeadingSubject:
161
159
  Exclude:
162
- - 'spec/unit/reloader_spec.rb'
163
160
 
164
161
  # Offense count: 2
165
162
  RSpec/LeakyConstantDeclaration:
@@ -196,7 +193,6 @@ RSpec/NamedSubject:
196
193
  - 'spec/support/contexts.rb'
197
194
  - 'spec/support/requirements.rb'
198
195
  - 'spec/tenant_spec.rb'
199
- - 'spec/unit/reloader_spec.rb'
200
196
 
201
197
  # Offense count: 24
202
198
  RSpec/NestedGroups:
@@ -217,7 +213,6 @@ RSpec/VerifiedDoubles:
217
213
  Exclude:
218
214
  - 'spec/integration/apartment_rake_integration_spec.rb'
219
215
  - 'spec/unit/elevators/first_subdomain_spec.rb'
220
- - 'spec/unit/reloader_spec.rb'
221
216
 
222
217
  # Offense count: 17
223
218
  Style/Documentation:
@@ -233,7 +228,6 @@ Style/Documentation:
233
228
  - 'lib/apartment/migrator.rb'
234
229
  - 'lib/apartment/model.rb'
235
230
  - 'lib/apartment/railtie.rb'
236
- - 'lib/apartment/reloader.rb'
237
231
  - 'lib/apartment/tasks/enhancements.rb'
238
232
  - 'lib/apartment/tasks/task_helper.rb'
239
233
  - 'lib/generators/apartment/install/install_generator.rb'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.3
1
+ 2.7.5
data/Appraisals CHANGED
@@ -1,29 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'rails-5-0' do
4
- gem 'rails', '~> 5.0.0'
5
- platforms :ruby do
6
- gem 'pg', '< 1.0.0'
7
- end
8
- platforms :jruby do
9
- gem 'activerecord-jdbc-adapter', '~> 50.0'
10
- gem 'activerecord-jdbcpostgresql-adapter', '~> 50.0'
11
- gem 'activerecord-jdbcmysql-adapter', '~> 50.0'
12
- end
13
- end
14
-
15
- appraise 'rails-5-1' do
16
- gem 'rails', '~> 5.1.0'
17
- platforms :ruby do
18
- gem 'pg', '< 1.0.0'
19
- end
20
- platforms :jruby do
21
- gem 'activerecord-jdbc-adapter', '~> 51.0'
22
- gem 'activerecord-jdbcpostgresql-adapter', '~> 51.0'
23
- gem 'activerecord-jdbcmysql-adapter', '~> 51.0'
24
- end
25
- end
26
-
27
3
  appraise 'rails-5-2' do
28
4
  gem 'rails', '~> 5.2.0'
29
5
  platforms :jruby do
@@ -57,6 +33,18 @@ appraise 'rails-6-1' do
57
33
  end
58
34
  end
59
35
 
36
+ appraise 'rails-7-0' do
37
+ gem 'rails', '~> 7.0.0'
38
+ platforms :ruby do
39
+ gem 'sqlite3', '~> 1.4'
40
+ end
41
+ platforms :jruby do
42
+ gem 'activerecord-jdbc-adapter', '~> 61.0'
43
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 61.0'
44
+ gem 'activerecord-jdbcmysql-adapter', '~> 61.0'
45
+ end
46
+ end
47
+
60
48
  appraise 'rails-master' do
61
49
  gem 'rails', git: 'https://github.com/rails/rails.git'
62
50
  platforms :ruby do
data/README.md CHANGED
@@ -344,7 +344,7 @@ Setting this configuration value to `false` will disable the schema presence che
344
344
 
345
345
  ```ruby
346
346
  Apartment.configure do |config|
347
- tenant_presence_check = false
347
+ config.tenant_presence_check = false
348
348
  end
349
349
  ```
350
350
 
@@ -3,12 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.2.0"
6
- gem "rubocop"
7
-
8
- group :local do
9
- gem "guard-rspec", "~> 4.2"
10
- gem "pry"
11
- end
12
6
 
13
7
  platforms :jruby do
14
8
  gem "activerecord-jdbc-adapter", "~> 52.0"
@@ -3,12 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.0.0"
6
- gem "rubocop"
7
-
8
- group :local do
9
- gem "guard-rspec", "~> 4.2"
10
- gem "pry"
11
- end
12
6
 
13
7
  platforms :ruby do
14
8
  gem "sqlite3", "~> 1.4"
@@ -3,12 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.1.0"
6
- gem "rubocop"
7
-
8
- group :local do
9
- gem "guard-rspec", "~> 4.2"
10
- gem "pry"
11
- end
12
6
 
13
7
  platforms :ruby do
14
8
  gem "sqlite3", "~> 1.4"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 7.0.0"
6
+
7
+ platforms :ruby do
8
+ gem "sqlite3", "~> 1.4"
9
+ end
10
+
11
+ platforms :jruby do
12
+ gem "activerecord-jdbc-adapter", "~> 61.0"
13
+ gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
14
+ gem "activerecord-jdbcmysql-adapter", "~> 61.0"
15
+ end
16
+
17
+ gemspec path: "../"
@@ -3,21 +3,15 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", git: "https://github.com/rails/rails.git"
6
- gem "rubocop"
7
-
8
- group :local do
9
- gem "guard-rspec", "~> 4.2"
10
- gem "pry"
11
- end
12
6
 
13
7
  platforms :ruby do
14
8
  gem "sqlite3", "~> 1.4"
15
9
  end
16
10
 
17
11
  platforms :jruby do
18
- gem "activerecord-jdbc-adapter", "~> 52.0"
19
- gem "activerecord-jdbcpostgresql-adapter", "~> 52.0"
20
- gem "activerecord-jdbcmysql-adapter", "~> 52.0"
12
+ gem "activerecord-jdbc-adapter", "~> 61.0"
13
+ gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
14
+ gem "activerecord-jdbcmysql-adapter", "~> 61.0"
21
15
  end
22
16
 
23
17
  gemspec path: "../"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Style/ClassAndModuleChildren
4
+
5
+ # NOTE: This patch is meant to remove any schema_prefix appart from the ones for
6
+ # excluded models. The schema_prefix would be resolved by apartment's setting
7
+ # of search path
8
+ module Apartment::PostgreSqlAdapterPatch
9
+ def default_sequence_name(table, _column)
10
+ res = super
11
+ schema_prefix = "#{Apartment::Tenant.current}."
12
+ default_tenant_prefix = "#{Apartment::Tenant.default_tenant}."
13
+
14
+ # NOTE: Excluded models should always access the sequence from the default
15
+ # tenant schema
16
+ if excluded_model?(table)
17
+ res.sub!(schema_prefix, default_tenant_prefix) if schema_prefix != default_tenant_prefix
18
+ return res
19
+ end
20
+
21
+ res.delete_prefix!(schema_prefix) if res&.starts_with?(schema_prefix)
22
+
23
+ res
24
+ end
25
+
26
+ private
27
+
28
+ def excluded_model?(table)
29
+ Apartment.excluded_models.any? { |m| m.constantize.table_name == table }
30
+ end
31
+ end
32
+
33
+ require 'active_record/connection_adapters/postgresql_adapter'
34
+
35
+ # NOTE: inject this into postgresql adapters
36
+ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
37
+ include Apartment::PostgreSqlAdapterPatch
38
+ end
39
+ # rubocop:enable Style/ClassAndModuleChildren
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'apartment/adapters/abstract_adapter'
4
+ require 'apartment/active_record/postgresql_adapter'
4
5
 
5
6
  module Apartment
6
7
  module Tenant
@@ -41,7 +42,6 @@ module Apartment
41
42
  def reset
42
43
  @current = default_tenant
43
44
  Apartment.connection.schema_search_path = full_search_path
44
- reset_sequence_names
45
45
  end
46
46
 
47
47
  def init
@@ -81,9 +81,8 @@ module Apartment
81
81
  # there is a issue for prepared statement with changing search_path.
82
82
  # https://www.postgresql.org/docs/9.3/static/sql-prepare.html
83
83
  Apartment.connection.clear_cache! if postgresql_version < 90_300
84
- reset_sequence_names
85
- rescue *rescuable_exceptions
86
- raise TenantNotFound, "One of the following schema(s) is invalid: \"#{tenant}\" #{full_search_path}"
84
+ rescue *rescuable_exceptions => e
85
+ raise_schema_connect_to_new(tenant, e)
87
86
  end
88
87
 
89
88
  private
@@ -130,29 +129,18 @@ module Apartment
130
129
  Apartment.connection.send(:postgresql_version)
131
130
  end
132
131
 
133
- def reset_sequence_names
134
- # sequence_name contains the schema, so it must be reset after switch
135
- # There is `reset_sequence_name`, but that method actually goes to the database
136
- # to find out the new name. Therefore, we do this hack to only unset the name,
137
- # and it will be dynamically found the next time it is needed
138
- descendants_to_unset = ActiveRecord::Base.descendants
139
- .select { |c| c.instance_variable_defined?(:@sequence_name) }
140
- .reject do |c|
141
- c.instance_variable_defined?(:@explicit_sequence_name) &&
142
- c.instance_variable_get(:@explicit_sequence_name)
143
- end
144
- descendants_to_unset.each do |c|
145
- # NOTE: due to this https://github.com/rails-on-services/apartment/issues/81
146
- # unreproduceable error we're checking before trying to remove it
147
- c.remove_instance_variable :@sequence_name if c.instance_variable_defined?(:@sequence_name)
148
- end
149
- end
150
-
151
132
  def schema_exists?(schemas)
152
133
  return true unless Apartment.tenant_presence_check
153
134
 
154
135
  Array(schemas).all? { |schema| Apartment.connection.schema_exists?(schema.to_s) }
155
136
  end
137
+
138
+ def raise_schema_connect_to_new(tenant, exception)
139
+ raise TenantNotFound, <<~EXCEPTION_MESSAGE
140
+ Could not set search path to schemas, they may be invalid: "#{tenant}" #{full_search_path}.
141
+ Original error: #{exception.class}: #{exception}
142
+ EXCEPTION_MESSAGE
143
+ end
156
144
  end
157
145
 
158
146
  # Another Adapter for Postgresql when using schemas and SQL
@@ -1,21 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # A workaround to get `reload!` to also call Apartment::Tenant.init
4
- # This is unfortunate, but I haven't figured out how to hook into the reload process *after* files are reloaded
5
-
6
- # reloads the environment
7
- # rubocop:disable Style/OptionalBooleanParameter
8
- def reload!(print = true)
9
- puts 'Reloading...' if print
10
-
11
- # This triggers the to_prepare callbacks
12
- ActionDispatch::Callbacks.new(proc {}).call({})
13
- # Manually init Apartment again once classes are reloaded
14
- Apartment::Tenant.init
15
- true
16
- end
17
- # rubocop:enable Style/OptionalBooleanParameter
18
-
19
3
  def st(schema_name = nil)
20
4
  if schema_name.nil?
21
5
  tenant_list.each { |t| puts t }
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'rails'
4
4
  require 'apartment/tenant'
5
- require 'apartment/reloader'
6
5
 
7
6
  module Apartment
8
7
  class Railtie < Rails::Railtie
@@ -60,23 +59,5 @@ module Apartment
60
59
  load 'tasks/apartment.rake'
61
60
  require 'apartment/tasks/enhancements' if Apartment.db_migrate_tenants
62
61
  end
63
-
64
- #
65
- # The following initializers are a workaround to the fact that I can't properly hook into the rails reloader
66
- # Note this is technically valid for any environment where cache_classes is false, for us, it's just development
67
- #
68
- if Rails.env.development?
69
-
70
- # Apartment::Reloader is middleware to initialize things properly on each request to dev
71
- initializer 'apartment.init' do |app|
72
- app.config.middleware.use Apartment::Reloader
73
- end
74
-
75
- # Overrides reload! to also call Apartment::Tenant.init as well
76
- # so that the reloaded classes have the proper table_names
77
- console do
78
- require 'apartment/console'
79
- end
80
- end
81
62
  end
82
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apartment
4
- VERSION = '2.10.0'
4
+ VERSION = '2.11.0'
5
5
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.homepage = 'https://github.com/rails-on-services/apartment'
28
28
  s.licenses = ['MIT']
29
29
 
30
- s.add_dependency 'activerecord', '>= 5.0.0', '< 6.2'
30
+ s.add_dependency 'activerecord', '>= 5.0.0', '< 7.1'
31
31
  s.add_dependency 'parallel', '< 2.0'
32
32
  s.add_dependency 'public_suffix', '>= 2.0.5', '< 5.0'
33
33
  s.add_dependency 'rack', '>= 1.3.6', '< 3.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ros-apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-09-13 00:00:00.000000000 Z
13
+ date: 2022-02-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 5.0.0
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '6.2'
24
+ version: '7.1'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: 5.0.0
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '6.2'
34
+ version: '7.1'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: parallel
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -332,16 +332,15 @@ files:
332
332
  - Rakefile
333
333
  - TODO.md
334
334
  - docker-compose.yml
335
- - gemfiles/rails_4_2.gemfile
336
- - gemfiles/rails_5_0.gemfile
337
- - gemfiles/rails_5_1.gemfile
338
335
  - gemfiles/rails_5_2.gemfile
339
336
  - gemfiles/rails_6_0.gemfile
340
337
  - gemfiles/rails_6_1.gemfile
338
+ - gemfiles/rails_7_0.gemfile
341
339
  - gemfiles/rails_master.gemfile
342
340
  - lib/apartment.rb
343
341
  - lib/apartment/active_record/connection_handling.rb
344
342
  - lib/apartment/active_record/internal_metadata.rb
343
+ - lib/apartment/active_record/postgresql_adapter.rb
345
344
  - lib/apartment/active_record/schema_migration.rb
346
345
  - lib/apartment/adapters/abstract_adapter.rb
347
346
  - lib/apartment/adapters/abstract_jdbc_adapter.rb
@@ -364,7 +363,6 @@ files:
364
363
  - lib/apartment/migrator.rb
365
364
  - lib/apartment/model.rb
366
365
  - lib/apartment/railtie.rb
367
- - lib/apartment/reloader.rb
368
366
  - lib/apartment/tasks/enhancements.rb
369
367
  - lib/apartment/tasks/task_helper.rb
370
368
  - lib/apartment/tenant.rb
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This file was generated by Appraisal
4
-
5
- source 'http://rubygems.org'
6
-
7
- gem 'rails', '~> 4.2.0'
8
-
9
- group :local do
10
- gem 'guard-rspec', '~> 4.2'
11
- gem 'pry'
12
- end
13
-
14
- platforms :ruby do
15
- gem 'mysql2', '~> 0.4.0'
16
- gem 'pg', '< 1.0.0'
17
- end
18
-
19
- platforms :jruby do
20
- gem 'activerecord-jdbc-adapter', '~> 1.3'
21
- gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
22
- gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
23
- end
24
-
25
- gemspec path: '../'
@@ -1,23 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 5.0.0"
6
- gem "rubocop"
7
-
8
- group :local do
9
- gem "guard-rspec", "~> 4.2"
10
- gem "pry"
11
- end
12
-
13
- platforms :ruby do
14
- gem "pg", "< 1.0.0"
15
- end
16
-
17
- platforms :jruby do
18
- gem "activerecord-jdbc-adapter", "~> 50.0"
19
- gem "activerecord-jdbcpostgresql-adapter", "~> 50.0"
20
- gem "activerecord-jdbcmysql-adapter", "~> 50.0"
21
- end
22
-
23
- gemspec path: "../"
@@ -1,23 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "~> 5.1.0"
6
- gem "rubocop"
7
-
8
- group :local do
9
- gem "guard-rspec", "~> 4.2"
10
- gem "pry"
11
- end
12
-
13
- platforms :ruby do
14
- gem "pg", "< 1.0.0"
15
- end
16
-
17
- platforms :jruby do
18
- gem "activerecord-jdbc-adapter", "~> 51.0"
19
- gem "activerecord-jdbcpostgresql-adapter", "~> 51.0"
20
- gem "activerecord-jdbcmysql-adapter", "~> 51.0"
21
- end
22
-
23
- gemspec path: "../"
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Apartment
4
- class Reloader
5
- # Middleware used in development to init Apartment for each request
6
- # Necessary due to code reload (annoying). When models are reloaded, they no longer have the proper table_name
7
- # That is prepended with the schema (if using postgresql schemas)
8
- # I couldn't figure out how to properly hook into the Rails reload process *after* files are reloaded
9
- # so I've used this in the meantime.
10
- #
11
- # Also see apartment/console for the re-definition of reload! that re-init's Apartment
12
- #
13
- def initialize(app)
14
- @app = app
15
- end
16
-
17
- def call(env)
18
- Tenant.init
19
- @app.call(env)
20
- end
21
- end
22
- end