activerecord-multi-tenant 2.1.6 → 2.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
  SHA256:
3
- metadata.gz: 23f4082afb70ab964006573b094d2dd61a6aa0e015276504488d911578406f83
4
- data.tar.gz: 509ebd9c590c472b84bba4d17ed9880f80d88e7fade20ec35350148634732cf6
3
+ metadata.gz: 15ad19bf20781129dc1bd57d4e4b8eb8731044cea3b89f29a62789d0f5a45aee
4
+ data.tar.gz: 0f76290b00a7d540495972ab5a9de09d3abbb1dde11758d58b08493bf743b5da
5
5
  SHA512:
6
- metadata.gz: b359e5a9a001d1a20ad676fcf855eabe0dee36763245f779607942fe71ba937c8441fb944759790b3a07fb0dacb4cbff8bb329a17fac79de3468c7f1982c5b4b
7
- data.tar.gz: cae89438df5db59a4e7cc9b804cfc73745c0ad1879dfcf0c21b2aee804e3657304cc8c36ebc301a5da371ad29d7e616adecd4440c36d55c5a6413b858e13abda
6
+ metadata.gz: 17f7b912ecc314e5462affd74daf2e1b79239f8f65bfa30c8896f4acb9e1d787c240aeefe8cb09045b34ab2772d46aab4c42bb8cdb3374df247f1131a08758d0
7
+ data.tar.gz: 713df8fdefb6cd50b2c02408a9763da39e532b957d176fe5a8a6e1fbe265d2cf79457ae4d196d0e6ddfdf8effe0ca370c0297ea7186a5ce145717e4a93772be1
@@ -13,40 +13,24 @@ jobs:
13
13
  fail-fast: false
14
14
  matrix:
15
15
  ruby:
16
- - '2.5'
17
16
  - '2.6'
18
17
  - '2.7'
19
18
  - '3.0'
20
19
  - '3.1'
21
20
  gemfile:
22
- - rails_5.2
23
21
  - rails_6.0
24
22
  - rails_6.1
25
23
  - rails_7.0
26
- - active_record_5.2
27
24
  - active_record_6.0
28
25
  - active_record_6.1
29
26
  - active_record_7.0
30
27
  prepared_statements: [true, false]
31
28
  exclude:
32
29
  # activesupport-7.0.0 requires ruby version >= 2.7.0
33
- - ruby: '2.5'
34
- gemfile: 'rails_7.0'
35
- - ruby: '2.5'
36
- gemfile: 'active_record_7.0'
37
30
  - ruby: '2.6'
38
31
  gemfile: 'rails_7.0'
39
32
  - ruby: '2.6'
40
33
  gemfile: 'active_record_7.0'
41
- # ruby >3 and activesupport 5.2 are not compatible
42
- - ruby: '3.0'
43
- gemfile: 'rails_5.2'
44
- - ruby: '3.0'
45
- gemfile: 'active_record_5.2'
46
- - ruby: '3.1'
47
- gemfile: 'rails_5.2'
48
- - ruby: '3.1'
49
- gemfile: 'active_record_5.2'
50
34
  name: Ruby ${{ matrix.ruby }} / ${{ matrix.gemfile }} ${{ (matrix.prepared_statements && 'w/ prepared statements') || '' }}
51
35
  env:
52
36
  BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
data/Appraisals CHANGED
@@ -1,15 +1,3 @@
1
- appraise 'rails-5.2' do
2
- gem 'rails', '~> 5.2.0'
3
- gem 'i18n', '~> 0.9.5'
4
- gem 'nokogiri', '~> 1.7.1'
5
- gem 'nio4r', '~> 2.3.1'
6
- gem 'sprockets', '~> 3.7.1'
7
- gem 'byebug', '~> 11.0'
8
- gem 'rake', '12.0.0'
9
- gem 'redis', '3.3.3'
10
- gem 'pry-byebug', '3.9.0'
11
- end
12
-
13
1
  appraise 'rails-6.0' do
14
2
  gem 'rails', '~> 6.0.3'
15
3
  end
@@ -22,18 +10,6 @@ appraise 'rails-7.0' do
22
10
  gem 'rails', '~> 7.0.0'
23
11
  end
24
12
 
25
- appraise 'active-record-5.2' do
26
- gem 'activerecord', '~> 5.2.0'
27
- gem 'i18n', '~> 0.9.5'
28
- gem 'nokogiri', '~> 1.7.1'
29
- gem 'nio4r', '~> 2.3.1'
30
- gem 'sprockets', '~> 3.7.1'
31
- gem 'byebug', '~> 11.0'
32
- gem 'rake', '12.0.0'
33
- gem 'redis', '3.3.3'
34
- gem 'pry-byebug', '3.9.0'
35
- end
36
-
37
13
  appraise 'active-record-6.0' do
38
14
  gem 'activerecord', '~> 6.0.3'
39
15
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.2.0 2022-12-06
4
+ * Handle changing tenant from `nil` to a value [#173](https://github.com/citusdata/activerecord-multi-tenant/pull/173)
5
+ * Allow Partitioned tables to be created without a primary key [#172](https://github.com/citusdata/activerecord-multi-tenant/pull/172)
6
+ * Only attempt to reload with MultiTenant when parition_key is present [#175](https://github.com/citusdata/activerecord-multi-tenant/pull/175)
7
+ * Remove support for Ruby 2.5 & ActiveRecord 5.2
8
+
3
9
  ## 2.1.6 2022-11-23
4
10
  * Fix undefined wrap_methods error & wrap_methods version check [#170](https://github.com/citusdata/activerecord-multi-tenant/pull/170)
5
11
 
data/README.md CHANGED
@@ -16,7 +16,7 @@ gem 'activerecord-multi-tenant'
16
16
 
17
17
  ## Supported Rails versions
18
18
 
19
- All Ruby on Rails versions starting with 5.2 or newer (up to 7.0) are supported.
19
+ All Ruby on Rails versions starting with 6.0 or newer (up to 7.0) are supported.
20
20
 
21
21
  This gem only supports ActiveRecord (the Rails default ORM), and not alternative ORMs like Sequel.
22
22
 
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.homepage = 'https://github.com/citusdata/activerecord-multi-tenant'
16
16
  s.license = 'MIT'
17
17
 
18
- s.add_dependency 'rails', '>= 5.2'
18
+ s.add_dependency 'rails', '>= 6'
19
19
 
20
20
  s.add_development_dependency 'rspec', '>= 3.0'
21
21
  s.add_development_dependency 'rspec-rails'
@@ -71,7 +71,7 @@ module ActiveRecord
71
71
  alias orig_create_table create_table
72
72
  def create_table(table_name, options = {}, &block)
73
73
  ret = orig_create_table(table_name, **options.except(:partition_key), &block)
74
- if options[:partition_key] && options[:partition_key].to_s != 'id'
74
+ if options[:id] != false && options[:partition_key] && options[:partition_key].to_s != 'id'
75
75
  execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{table_name}_pkey"
76
76
  execute "ALTER TABLE #{table_name} ADD PRIMARY KEY(\"#{options[:partition_key]}\", id)"
77
77
  end
@@ -75,7 +75,6 @@ module MultiTenant
75
75
  # Rails 5 `attribute_will_change!` uses the attribute-method-call rather than `read_attribute`
76
76
  # and will raise ActiveModel::MissingAttributeError if that column was not selected.
77
77
  # This is rescued as NoMethodError and in MRI attribute_was is assigned an arbitrary Object
78
- # This is still true after the Rails 5.2 refactor
79
78
  was = send("#{partition_key}_was")
80
79
  was_nil_or_skipped = was.nil? || was.class == Object
81
80
 
@@ -102,7 +101,8 @@ module MultiTenant
102
101
  include to_include
103
102
 
104
103
  around_save -> (record, block) {
105
- if persisted? && MultiTenant.current_tenant_id.nil?
104
+ record_tenant = record.attribute_was(partition_key)
105
+ if persisted? && MultiTenant.current_tenant_id.nil? && !record_tenant.nil?
106
106
  MultiTenant.with(record.public_send(partition_key)) { block.call }
107
107
  else
108
108
  block.call
@@ -110,7 +110,8 @@ module MultiTenant
110
110
  }
111
111
 
112
112
  around_update -> (record, block) {
113
- if MultiTenant.current_tenant_id.nil?
113
+ record_tenant = record.attribute_was(partition_key)
114
+ if MultiTenant.current_tenant_id.nil? && !record_tenant.nil?
114
115
  MultiTenant.with(record.public_send(partition_key)) { block.call }
115
116
  else
116
117
  block.call
@@ -117,7 +117,7 @@ module MultiTenant
117
117
  klass.class_eval <<-CODE, __FILE__, __LINE__ + 1
118
118
  alias_method :#{original_method_name}, :#{method_name}
119
119
  def #{method_name}(*args, &block)
120
- if MultiTenant.multi_tenant_model_for_table(#{owner}.class.table_name).present? && #{owner}.persisted? && MultiTenant.current_tenant_id.nil?
120
+ if MultiTenant.multi_tenant_model_for_table(#{owner}.class.table_name).present? && #{owner}.persisted? && MultiTenant.current_tenant_id.nil? && #{owner}.class.respond_to?(:partition_key) && #{owner}.attributes.include?(#{owner}.class.partition_key)
121
121
  MultiTenant.with(#{owner}.public_send(#{owner}.class.partition_key)) { #{original_method_name}(*args, &block) }
122
122
  else
123
123
  #{original_method_name}(*args, &block)
@@ -133,7 +133,7 @@ module MultiTenant
133
133
  klass.class_eval <<-CODE, __FILE__, __LINE__ + 1
134
134
  alias_method :#{original_method_name}, :#{method_name}
135
135
  def #{method_name}(...)
136
- if MultiTenant.multi_tenant_model_for_table(#{owner}.class.table_name).present? && #{owner}.persisted? && MultiTenant.current_tenant_id.nil?
136
+ if MultiTenant.multi_tenant_model_for_table(#{owner}.class.table_name).present? && #{owner}.persisted? && MultiTenant.current_tenant_id.nil? && #{owner}.class.respond_to?(:partition_key) && #{owner}.attributes.include?(#{owner}.class.partition_key)
137
137
  MultiTenant.with(#{owner}.public_send(#{owner}.class.partition_key)) { #{original_method_name}(...) }
138
138
  else
139
139
  #{original_method_name}(...)
@@ -1,3 +1,3 @@
1
1
  module MultiTenant
2
- VERSION = '2.1.6'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -209,6 +209,16 @@ describe MultiTenant do
209
209
  expect(record.account_id).to eq(nil)
210
210
  end
211
211
 
212
+ it 'handles changing tenant from nil to a value' do
213
+ record = OptionalSubTask.create(sub_task_id: sub_task.id)
214
+ expect(record.reload.sub_task).to eq(sub_task)
215
+ expect(record.account_id).to eq(nil)
216
+
217
+ record.account = account
218
+ record.save!
219
+ expect(record.reload.account_id).to eq(account.id)
220
+ end
221
+
212
222
  it 'handles has_many through' do
213
223
  MultiTenant.with(account) do
214
224
  expect(project.sub_tasks).to eq [sub_task]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-multi-tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Citus Data
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-23 00:00:00.000000000 Z
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -154,11 +154,9 @@ files:
154
154
  - activerecord-multi-tenant.gemspec
155
155
  - docker-compose.yml
156
156
  - gemfiles/.bundle/config
157
- - gemfiles/active_record_5.2.gemfile
158
157
  - gemfiles/active_record_6.0.gemfile
159
158
  - gemfiles/active_record_6.1.gemfile
160
159
  - gemfiles/active_record_7.0.gemfile
161
- - gemfiles/rails_5.2.gemfile
162
160
  - gemfiles/rails_6.0.gemfile
163
161
  - gemfiles/rails_6.1.gemfile
164
162
  - gemfiles/rails_7.0.gemfile
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "activerecord", "~> 5.2.0"
7
- gem "i18n", "~> 0.9.5"
8
- gem "nokogiri", "~> 1.7.1"
9
- gem "nio4r", "~> 2.3.1"
10
- gem "sprockets", "~> 3.7.1"
11
- gem "byebug", "~> 11.0"
12
- gem "rake", "12.0.0"
13
- gem "redis", "3.3.3"
14
- gem "pry-byebug", "3.9.0"
15
-
16
- gemspec path: "../"
@@ -1,16 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rails", "~> 5.2.0"
7
- gem "i18n", "~> 0.9.5"
8
- gem "nokogiri", "~> 1.7.1"
9
- gem "nio4r", "~> 2.3.1"
10
- gem "sprockets", "~> 3.7.1"
11
- gem "byebug", "~> 11.0"
12
- gem "rake", "12.0.0"
13
- gem "redis", "3.3.3"
14
- gem "pry-byebug", "3.9.0"
15
-
16
- gemspec path: "../"