activerecord-multi-tenant 2.1.3 → 2.1.5

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: 29d653eb35952bb70e983799cae4b5c88fdcbf852e1ba16a730362a01f18d327
4
- data.tar.gz: 6fa61c33ed3f99eff5d214f195544547ac67bf4d81d60adbe18c4d1ecb7432a9
3
+ metadata.gz: fb96e241668d1b08b01d087f2223f7ae703a73e09412f67aadb297aa0bb43818
4
+ data.tar.gz: f8e964e5549e489c93baaf0ce61b150eac3f3bb7c327dbec7994288c096a535c
5
5
  SHA512:
6
- metadata.gz: 0f9b6bc791de06c8c3cfef7cd4f458cebe9412bbe0baf01f3ff102636810a3fa6b2f1ec63aacfd9c4989956f14fa78b4a29d862d399ae634cf44def50db7f594
7
- data.tar.gz: 46dcda19e38662c310d4c149f01151422461157c16012a07060f64735667d75ff1040956db0b7428ff7a76c2ee84b56facd77c86b063bfffed65e44341a37323
6
+ metadata.gz: 5746bb54fb98adf017c0c888b6993a2e82fcca9a0f56588e405230bc1750c63723f89b9664b8f2d31dc11cbd43a1ee43a9d4e39f1ba784f4f9fc09450245833c
7
+ data.tar.gz: 448dda3c1b4406afe5aa602aa965bc5be35b18cbd539f8cd28fdd626ea00b65970d993fe6ae637ffeca3c809c43ab556ae2fdfdadcac853923b3222e798c6dc1
@@ -19,12 +19,10 @@ jobs:
19
19
  - '3.0'
20
20
  - '3.1'
21
21
  gemfile:
22
- - rails_5.2.3
23
22
  - rails_5.2
24
23
  - rails_6.0
25
24
  - rails_6.1
26
25
  - rails_7.0
27
- - active_record_5.2.3
28
26
  - active_record_5.2
29
27
  - active_record_6.0
30
28
  - active_record_6.1
@@ -49,14 +47,6 @@ jobs:
49
47
  gemfile: 'rails_5.2'
50
48
  - ruby: '3.1'
51
49
  gemfile: 'active_record_5.2'
52
- - ruby: '3.0'
53
- gemfile: 'rails_5.2.3'
54
- - ruby: '3.0'
55
- gemfile: 'active_record_5.2.3'
56
- - ruby: '3.1'
57
- gemfile: 'rails_5.2.3'
58
- - ruby: '3.1'
59
- gemfile: 'active_record_5.2.3'
60
50
  name: Ruby ${{ matrix.ruby }} / ${{ matrix.gemfile }} ${{ (matrix.prepared_statements && 'w/ prepared statements') || '' }}
61
51
  env:
62
52
  BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.5 2022-11-20
4
+ * Fix `MultiTenant.without` codegen bug in Rails 6.1+ [#168](https://github.com/citusdata/activerecord-multi-tenant/pull/168)
5
+
6
+ ## 2.1.4 2022-11-03
7
+ * Fixes #166 where db:schema:dump is broken when using this gem with MySQL [#167](https://github.com/citusdata/activerecord-multi-tenant/pull/167)
8
+
3
9
  ## 2.1.3 2022-10-27
4
10
  * Error when calling a method that takes keyword arguments with MultiTenant.wrap_methods [#164](https://github.com/citusdata/activerecord-multi-tenant/pull/164)
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 4.2 or newer (up to 6.0) are supported.
19
+ All Ruby on Rails versions starting with 5.2 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
 
@@ -89,8 +89,14 @@ module ActiveRecord
89
89
  def initialize(connection, options = {})
90
90
  initialize_without_citus(connection, options)
91
91
 
92
+ citus_version = begin
93
+ ActiveRecord::Migration.citus_version
94
+ rescue StandardError
95
+ # Handle the case where this gem is used with MySQL https://github.com/citusdata/activerecord-multi-tenant/issues/166
96
+ nil
97
+ end
92
98
  @distribution_columns =
93
- if ActiveRecord::Migration.citus_version.present?
99
+ if citus_version.present?
94
100
  @connection.execute('SELECT logicalrelid::regclass AS table_name, column_to_column_name(logicalrelid, partkey) AS dist_col_name FROM pg_dist_partition').to_h do |v|
95
101
  [v['table_name'], v['dist_col_name']]
96
102
  end
@@ -330,8 +330,9 @@ module ActiveRecord
330
330
  return nil, nil
331
331
  end
332
332
 
333
- if children[0].right.respond_to?('relation') && children[0].left.respond_to?('relation')
334
- return children[0].right.relation, children[0].left.relation
333
+ child = children.first.respond_to?(:children) ? children.first.children.first : children.first
334
+ if child.right.respond_to?(:relation) && child.left.respond_to?(:relation)
335
+ return child.right.relation, child.left.relation
335
336
  end
336
337
 
337
338
  return nil, nil
@@ -1,3 +1,3 @@
1
1
  module MultiTenant
2
- VERSION = '2.1.3'
2
+ VERSION = '2.1.5'
3
3
  end
@@ -299,6 +299,55 @@ describe MultiTenant do
299
299
  end
300
300
  end
301
301
 
302
+ # Joins
303
+ describe 'joins for models' do
304
+ context 'for models with where condition in associations' do
305
+ let(:account) { Account.create!(name: 'Account 1') }
306
+
307
+ it 'should add tenant condition to the queries when tenant is set' do
308
+ expected_join_sql = <<-SQL.strip
309
+ SELECT "comments".* FROM "comments" INNER JOIN "tasks" ON "tasks"."id" = "comments"."commentable_id" AND "comments"."commentable_type" = 'Task' AND "tasks"."account_id" = 1 WHERE "comments"."account_id" = 1
310
+ SQL
311
+
312
+ MultiTenant.with(account) do
313
+ expect(Comment.joins(:task).to_sql).to eq(expected_join_sql)
314
+ end
315
+ end
316
+
317
+ it 'should add tenant condition to the queries when tenant is not set' do
318
+ MultiTenant.without do
319
+ expected_join_sql = <<-SQL.strip
320
+ SELECT "comments".* FROM "comments" INNER JOIN "tasks" ON "tasks"."id" = "comments"."commentable_id" AND "comments"."commentable_type" = 'Task' AND "comments"."account_id" = "tasks"."account_id"
321
+ SQL
322
+ expect(Comment.joins(:task).to_sql).to eq(expected_join_sql)
323
+ end
324
+ end
325
+ end
326
+
327
+ context 'for models with default associations' do
328
+ let(:account) { Account.create!(name: 'Account 1') }
329
+
330
+ it 'should add tenant condition to the queries when tenant is set' do
331
+ expected_join_sql = <<-SQL.strip
332
+ SELECT "projects".* FROM "projects" INNER JOIN "tasks" ON "tasks"."project_id" = "projects"."id" AND "tasks"."account_id" = 1 WHERE "projects"."account_id" = 1
333
+ SQL
334
+
335
+ MultiTenant.with(account) do
336
+ expect(Project.joins(:tasks).to_sql).to eq(expected_join_sql)
337
+ end
338
+ end
339
+
340
+ it 'should add tenant condition to the queries when tenant is not set' do
341
+ MultiTenant.without do
342
+ expected_join_sql = <<-SQL.strip
343
+ SELECT "projects".* FROM "projects" INNER JOIN "tasks" ON "tasks"."project_id" = "projects"."id" AND "projects"."account_id" = "tasks"."account_id"
344
+ SQL
345
+ expect(Project.joins(:tasks).to_sql).to eq(expected_join_sql)
346
+ end
347
+ end
348
+ end
349
+ end
350
+
302
351
  # ::with
303
352
  describe "::with" do
304
353
  it "should set current_tenant to the specified tenant inside the block" do
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.3
4
+ version: 2.1.5
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-10-27 00:00:00.000000000 Z
11
+ date: 2022-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -154,12 +154,10 @@ files:
154
154
  - activerecord-multi-tenant.gemspec
155
155
  - docker-compose.yml
156
156
  - gemfiles/.bundle/config
157
- - gemfiles/active_record_5.2.3.gemfile
158
157
  - gemfiles/active_record_5.2.gemfile
159
158
  - gemfiles/active_record_6.0.gemfile
160
159
  - gemfiles/active_record_6.1.gemfile
161
160
  - gemfiles/active_record_7.0.gemfile
162
- - gemfiles/rails_5.2.3.gemfile
163
161
  - gemfiles/rails_5.2.gemfile
164
162
  - gemfiles/rails_6.0.gemfile
165
163
  - gemfiles/rails_6.1.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", "< 5.2.4" # FIXME
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", "< 5.2.4" # FIXME
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: "../"