activerecord-multi-tenant 0.11.0 → 1.0.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: 63718531a69f576dfff1966daa127d22a90501d8d367c59cfa14ed60f0e11d11
4
- data.tar.gz: d19ff33cd3ba08237015186e87a5c92910292561962e3fde49e128b341067eea
3
+ metadata.gz: e167475943bea775b41d11e80881d5938607281e76076b5d0d847651a626f9ff
4
+ data.tar.gz: 2bbf2defbe8dd5c2b7e05b65f74bc55db00ce39d02dee2ee99f5b23f4cd5eee5
5
5
  SHA512:
6
- metadata.gz: 959702bc65ece2ca74c92e7a2e07f2429c2aba56c5c64517b5625aab2ccd2efe1eb7639a7070c08ad617e63a3fc218a07f0ff4d4383598304108467dc31434cb
7
- data.tar.gz: 2eefe3dd780f6bd2ad1ead39e23ed185db777ec3cf84257b29c370e4f774cd80650435cdb3a86a9d25561d53dfaab3e5e28ee1147a5dabe6119ef7acca118a17
6
+ metadata.gz: 867f0dbe076cdf879d6e391bcce94e8bf4dd50a72afbec4a6dd0d386d1d245bf0f8fcd7b68b1e76b6eddd6340720d176a18781bf5afd2e4be58fbd87e02bbd0a
7
+ data.tar.gz: cfb1c04cb18a416501752cb308174e2f4a3167d830701f36c9a76065574d308311206aad8c26a43d4bcb9fea8e326d565e850ebcda4931e1da5c2d8289c378b0
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
 
3
3
 
4
+ ## 1.0.0 2019-07-05
5
+
6
+ * Fix `RETURNING id` for distributed tables with no primary key
7
+ * Include fix for partial select described in issue [#34](https://github.com/citusdata/activerecord-multi-tenant/issues/34).
8
+ - When doing a partial select without the tenant like `Project.select(:name).find(project.id)` it would raise `ActiveModel::MissingAttributeError (missing attribute: tenant_id)`
9
+
10
+
4
11
  ## 0.11.0 2019-06-12
5
12
 
6
13
  * Fix queries with joins by including the tenant column when current tenant isn't set
@@ -1,50 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-multi-tenant (0.11.0)
4
+ activerecord-multi-tenant (1.0.0)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (5.2.2)
12
- actionpack (= 5.2.2)
11
+ actioncable (5.2.3)
12
+ actionpack (= 5.2.3)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailer (5.2.2)
16
- actionpack (= 5.2.2)
17
- actionview (= 5.2.2)
18
- activejob (= 5.2.2)
15
+ actionmailer (5.2.3)
16
+ actionpack (= 5.2.3)
17
+ actionview (= 5.2.3)
18
+ activejob (= 5.2.3)
19
19
  mail (~> 2.5, >= 2.5.4)
20
20
  rails-dom-testing (~> 2.0)
21
- actionpack (5.2.2)
22
- actionview (= 5.2.2)
23
- activesupport (= 5.2.2)
21
+ actionpack (5.2.3)
22
+ actionview (= 5.2.3)
23
+ activesupport (= 5.2.3)
24
24
  rack (~> 2.0)
25
25
  rack-test (>= 0.6.3)
26
26
  rails-dom-testing (~> 2.0)
27
27
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
- actionview (5.2.2)
29
- activesupport (= 5.2.2)
28
+ actionview (5.2.3)
29
+ activesupport (= 5.2.3)
30
30
  builder (~> 3.1)
31
31
  erubi (~> 1.4)
32
32
  rails-dom-testing (~> 2.0)
33
33
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
- activejob (5.2.2)
35
- activesupport (= 5.2.2)
34
+ activejob (5.2.3)
35
+ activesupport (= 5.2.3)
36
36
  globalid (>= 0.3.6)
37
- activemodel (5.2.2)
38
- activesupport (= 5.2.2)
39
- activerecord (5.2.2)
40
- activemodel (= 5.2.2)
41
- activesupport (= 5.2.2)
37
+ activemodel (5.2.3)
38
+ activesupport (= 5.2.3)
39
+ activerecord (5.2.3)
40
+ activemodel (= 5.2.3)
41
+ activesupport (= 5.2.3)
42
42
  arel (>= 9.0)
43
- activestorage (5.2.2)
44
- actionpack (= 5.2.2)
45
- activerecord (= 5.2.2)
43
+ activestorage (5.2.3)
44
+ actionpack (= 5.2.3)
45
+ activerecord (= 5.2.3)
46
46
  marcel (~> 0.3.1)
47
- activesupport (5.2.2)
47
+ activesupport (5.2.3)
48
48
  concurrent-ruby (~> 1.0, >= 1.0.2)
49
49
  i18n (>= 0.7, < 2)
50
50
  minitest (~> 5.1)
@@ -55,16 +55,16 @@ GEM
55
55
  thor (>= 0.14.0)
56
56
  arel (9.0.0)
57
57
  builder (3.2.3)
58
- byebug (9.0.6)
59
- coderay (1.1.1)
60
- concurrent-ruby (1.1.3)
61
- connection_pool (2.2.1)
58
+ byebug (11.0.1)
59
+ coderay (1.1.2)
60
+ concurrent-ruby (1.1.5)
61
+ connection_pool (2.2.2)
62
62
  crass (1.0.4)
63
- diff-lcs (1.2.5)
64
- erubi (1.7.1)
63
+ diff-lcs (1.3)
64
+ erubi (1.8.0)
65
65
  globalid (0.4.2)
66
66
  activesupport (>= 4.2.0)
67
- i18n (1.1.1)
67
+ i18n (1.6.0)
68
68
  concurrent-ruby (~> 1.0)
69
69
  loofah (2.2.3)
70
70
  crass (~> 1.0.2)
@@ -73,82 +73,80 @@ GEM
73
73
  mini_mime (>= 0.1.1)
74
74
  marcel (0.3.3)
75
75
  mimemagic (~> 0.3.2)
76
- method_source (0.8.2)
76
+ method_source (0.9.2)
77
77
  mimemagic (0.3.3)
78
- mini_mime (1.0.1)
79
- mini_portile2 (2.3.0)
78
+ mini_mime (1.0.2)
79
+ mini_portile2 (2.4.0)
80
80
  minitest (5.11.3)
81
- nio4r (2.3.1)
82
- nokogiri (1.8.5)
83
- mini_portile2 (~> 2.3.0)
84
- pg (0.19.0)
85
- pry (0.10.4)
81
+ nio4r (2.4.0)
82
+ nokogiri (1.10.3)
83
+ mini_portile2 (~> 2.4.0)
84
+ pg (1.1.4)
85
+ pry (0.12.2)
86
86
  coderay (~> 1.1.0)
87
- method_source (~> 0.8.1)
88
- slop (~> 3.4)
89
- pry-byebug (3.4.2)
90
- byebug (~> 9.0)
87
+ method_source (~> 0.9.0)
88
+ pry-byebug (3.7.0)
89
+ byebug (~> 11.0)
91
90
  pry (~> 0.10)
92
- rack (2.0.6)
93
- rack-protection (2.0.1)
91
+ rack (2.0.7)
92
+ rack-protection (2.0.5)
94
93
  rack
95
94
  rack-test (1.1.0)
96
95
  rack (>= 1.0, < 3)
97
- rails (5.2.2)
98
- actioncable (= 5.2.2)
99
- actionmailer (= 5.2.2)
100
- actionpack (= 5.2.2)
101
- actionview (= 5.2.2)
102
- activejob (= 5.2.2)
103
- activemodel (= 5.2.2)
104
- activerecord (= 5.2.2)
105
- activestorage (= 5.2.2)
106
- activesupport (= 5.2.2)
96
+ rails (5.2.3)
97
+ actioncable (= 5.2.3)
98
+ actionmailer (= 5.2.3)
99
+ actionpack (= 5.2.3)
100
+ actionview (= 5.2.3)
101
+ activejob (= 5.2.3)
102
+ activemodel (= 5.2.3)
103
+ activerecord (= 5.2.3)
104
+ activestorage (= 5.2.3)
105
+ activesupport (= 5.2.3)
107
106
  bundler (>= 1.3.0)
108
- railties (= 5.2.2)
107
+ railties (= 5.2.3)
109
108
  sprockets-rails (>= 2.0.0)
110
109
  rails-dom-testing (2.0.3)
111
110
  activesupport (>= 4.2.0)
112
111
  nokogiri (>= 1.6)
113
112
  rails-html-sanitizer (1.0.4)
114
113
  loofah (~> 2.2, >= 2.2.2)
115
- railties (5.2.2)
116
- actionpack (= 5.2.2)
117
- activesupport (= 5.2.2)
114
+ railties (5.2.3)
115
+ actionpack (= 5.2.3)
116
+ activesupport (= 5.2.3)
118
117
  method_source
119
118
  rake (>= 0.8.7)
120
119
  thor (>= 0.19.0, < 2.0)
121
- rake (12.3.1)
122
- redis (3.3.3)
120
+ rake (12.3.2)
121
+ redis (4.1.2)
123
122
  request_store (1.4.1)
124
123
  rack (>= 1.4)
125
- rspec (3.5.0)
126
- rspec-core (~> 3.5.0)
127
- rspec-expectations (~> 3.5.0)
128
- rspec-mocks (~> 3.5.0)
129
- rspec-core (3.5.4)
130
- rspec-support (~> 3.5.0)
131
- rspec-expectations (3.5.0)
124
+ rspec (3.8.0)
125
+ rspec-core (~> 3.8.0)
126
+ rspec-expectations (~> 3.8.0)
127
+ rspec-mocks (~> 3.8.0)
128
+ rspec-core (3.8.2)
129
+ rspec-support (~> 3.8.0)
130
+ rspec-expectations (3.8.4)
132
131
  diff-lcs (>= 1.2.0, < 2.0)
133
- rspec-support (~> 3.5.0)
134
- rspec-mocks (3.5.0)
132
+ rspec-support (~> 3.8.0)
133
+ rspec-mocks (3.8.1)
135
134
  diff-lcs (>= 1.2.0, < 2.0)
136
- rspec-support (~> 3.5.0)
137
- rspec-rails (3.5.2)
135
+ rspec-support (~> 3.8.0)
136
+ rspec-rails (3.8.2)
138
137
  actionpack (>= 3.0)
139
138
  activesupport (>= 3.0)
140
139
  railties (>= 3.0)
141
- rspec-core (~> 3.5.0)
142
- rspec-expectations (~> 3.5.0)
143
- rspec-mocks (~> 3.5.0)
144
- rspec-support (~> 3.5.0)
145
- rspec-support (3.5.0)
146
- sidekiq (4.2.10)
147
- concurrent-ruby (~> 1.0)
148
- connection_pool (~> 2.2, >= 2.2.0)
140
+ rspec-core (~> 3.8.0)
141
+ rspec-expectations (~> 3.8.0)
142
+ rspec-mocks (~> 3.8.0)
143
+ rspec-support (~> 3.8.0)
144
+ rspec-support (3.8.2)
145
+ sidekiq (5.2.7)
146
+ connection_pool (~> 2.2, >= 2.2.2)
147
+ rack (>= 1.5.0)
149
148
  rack-protection (>= 1.5.0)
150
- redis (~> 3.2, >= 3.2.1)
151
- slop (3.6.0)
149
+ redis (>= 3.3.5, < 5)
152
150
  sprockets (3.7.2)
153
151
  concurrent-ruby (~> 1.0)
154
152
  rack (> 1, < 3)
@@ -160,9 +158,9 @@ GEM
160
158
  thread_safe (0.3.6)
161
159
  tzinfo (1.2.5)
162
160
  thread_safe (~> 0.1)
163
- websocket-driver (0.7.0)
161
+ websocket-driver (0.7.1)
164
162
  websocket-extensions (>= 0.1.0)
165
- websocket-extensions (0.1.3)
163
+ websocket-extensions (0.1.4)
166
164
 
167
165
  PLATFORMS
168
166
  ruby
@@ -180,4 +178,4 @@ DEPENDENCIES
180
178
  thor
181
179
 
182
180
  BUNDLED WITH
183
- 1.16.4
181
+ 1.17.2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (0.11.0)
4
+ activerecord-multi-tenant (1.0.0)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (0.11.0)
4
+ activerecord-multi-tenant (1.0.0)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (0.11.0)
4
+ activerecord-multi-tenant (1.0.0)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (0.11.0)
4
+ activerecord-multi-tenant (1.0.0)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (0.11.0)
4
+ activerecord-multi-tenant (1.0.0)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (0.11.0)
4
+ activerecord-multi-tenant (1.0.0)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (0.11.0)
4
+ activerecord-multi-tenant (1.0.0)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-multi-tenant (0.11.0)
4
+ activerecord-multi-tenant (1.0.0)
5
5
  rails (>= 4.0)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -23,13 +23,21 @@ module MultiTenant
23
23
  # Avoid primary_key errors when using composite primary keys (e.g. id, tenant_id)
24
24
  def primary_key
25
25
  return @primary_key if @primary_key
26
- return @primary_key = super || DEFAULT_ID_FIELD if ::ActiveRecord::VERSION::MAJOR < 5
26
+
27
+ if ::ActiveRecord::VERSION::MAJOR < 5
28
+ @primary_key = super || DEFAULT_ID_FIELD
29
+ return @primary_key if connection.schema_cache.columns_hash(table_name).include? @primary_key
30
+ end
27
31
 
28
32
  primary_object_keys = Array.wrap(connection.schema_cache.primary_keys(table_name)) - [partition_key]
33
+
29
34
  if primary_object_keys.size == 1
30
35
  @primary_key = primary_object_keys.first
31
- else
36
+ elsif connection.schema_cache.columns_hash(table_name).include? DEFAULT_ID_FIELD
32
37
  @primary_key = DEFAULT_ID_FIELD
38
+ else
39
+ # table without a primary key and DEFAULT_ID_FIELD is not present in the table
40
+ @primary_key = nil
33
41
  end
34
42
  end
35
43
 
@@ -51,7 +59,8 @@ module MultiTenant
51
59
 
52
60
  # New instances should have the tenant set
53
61
  after_initialize Proc.new { |record|
54
- if MultiTenant.current_tenant_id && record.public_send(partition_key.to_sym).nil?
62
+ if MultiTenant.current_tenant_id &&
63
+ (!record.attribute_present?(partition_key) || record.public_send(partition_key.to_sym).nil?)
55
64
  record.public_send("#{partition_key}=".to_sym, MultiTenant.current_tenant_id)
56
65
  end
57
66
  }
@@ -59,7 +68,15 @@ module MultiTenant
59
68
  to_include = Module.new do
60
69
  define_method "#{partition_key}=" do |tenant_id|
61
70
  write_attribute("#{partition_key}", tenant_id)
62
- raise MultiTenant::TenantIsImmutable if send("#{partition_key}_changed?") && persisted? && !send("#{partition_key}_was").nil?
71
+
72
+ # Rails 5 `attribute_will_change!` uses the attribute-method-call rather than `read_attribute`
73
+ # and will raise ActiveModel::MissingAttributeError if that column was not selected.
74
+ # This is rescued as NoMethodError and in MRI attribute_was is assigned an arbitrary Object
75
+ # This is still true after the Rails 5.2 refactor
76
+ was = send("#{partition_key}_was")
77
+ was_nil_or_skipped = was.nil? || was.class == Object
78
+
79
+ raise MultiTenant::TenantIsImmutable if send("#{partition_key}_changed?") && persisted? && !was_nil_or_skipped
63
80
  tenant_id
64
81
  end
65
82
 
@@ -1,3 +1,3 @@
1
1
  module MultiTenant
2
- VERSION = '0.11.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -44,6 +44,11 @@ describe MultiTenant do
44
44
  MultiTenant.current_tenant = @account
45
45
  end
46
46
  it {expect(Project.new.account_id).to eq(@account.id)}
47
+ it 'should handle partial selects' do
48
+ project = Project.create!
49
+ expect{project = Project.select(:name).find(project.id)}.not_to raise_error
50
+ expect(project.account_id).to eq(@account.id)
51
+ end
47
52
  end
48
53
 
49
54
  describe 'Handles custom partition_key on tenant model' do
@@ -573,4 +578,14 @@ describe MultiTenant do
573
578
  end
574
579
  end
575
580
  end
581
+
582
+ it "test value of RETURNING insert in table with no pkey" do
583
+ account1 = Account.create(name: 'test1')
584
+
585
+ MultiTenant.with(account1) do
586
+ allowed_place = AllowedPlace.create! name: 'something1'
587
+
588
+ project = Project.create! name: 'Project 1'
589
+ end
590
+ end
576
591
  end
@@ -89,6 +89,12 @@ ARGV.grep(/\w+_spec\.rb/).empty? && ActiveRecord::Schema.define(version: 1) do
89
89
  t.column :category_id, :integer
90
90
  end
91
91
 
92
+
93
+ create_table :allowed_places, force: true, id: false do |t|
94
+ t.string :account_id, :integer
95
+ t.string :name, :string
96
+ end
97
+
92
98
  create_distributed_table :accounts, :id
93
99
  create_distributed_table :projects, :account_id
94
100
  create_distributed_table :managers, :account_id
@@ -101,6 +107,7 @@ ARGV.grep(/\w+_spec\.rb/).empty? && ActiveRecord::Schema.define(version: 1) do
101
107
  create_distributed_table :subclass_tasks, :non_model_id
102
108
  create_distributed_table :uuid_records, :organization_id
103
109
  create_distributed_table :project_categories, :account_id
110
+ create_distributed_table :allowed_places, :account_id
104
111
  create_reference_table :categories
105
112
  end
106
113
 
@@ -199,3 +206,8 @@ class ProjectCategory < ActiveRecord::Base
199
206
  belongs_to :category
200
207
  belongs_to :account
201
208
  end
209
+
210
+
211
+ class AllowedPlace < ActiveRecord::Base
212
+ multi_tenant :account
213
+ end
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: 0.11.0
4
+ version: 1.0.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: 2019-06-13 00:00:00.000000000 Z
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: request_store