activerecord-multi-tenant 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/docker-compose.yml +11 -8
- data/gemfiles/active_record_5.1.gemfile.lock +1 -1
- data/gemfiles/rails_4.0.gemfile.lock +1 -1
- data/gemfiles/rails_4.1.gemfile.lock +1 -1
- data/gemfiles/rails_4.2.gemfile.lock +1 -1
- data/gemfiles/rails_5.0.gemfile.lock +1 -1
- data/gemfiles/rails_5.1.gemfile.lock +1 -1
- data/lib/activerecord-multi-tenant/query_rewriter.rb +24 -1
- data/lib/activerecord-multi-tenant/version.rb +1 -1
- data/spec/activerecord-multi-tenant/query_rewriter_spec.rb +32 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea9a26a7764b461bb053cb77385d032b68bec003
|
4
|
+
data.tar.gz: eb41e371832c04765affa48b9e484a604f35cef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31f075981d9b3f2bddc22648942c18425ecd8a30f78a4fb8535ece940c86461e7804f2c39f68b8fd01070e417234b8d54694de8fb803930ab8acbddd0952dcb3
|
7
|
+
data.tar.gz: c4e6b9305116e24a783db3efa200b952154976224411738a357bfbf6c084ea623f94382ae4f0d6bce8d1b194cde89733a5106401074ae6c2d55a7b4be9c5cf62
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.8.1 2017-10-06
|
4
|
+
|
5
|
+
* Cast attribute name to a string to avoid double applying tenant clause [Ben Olive](https://github.com/sionide21)
|
6
|
+
* Allow bulk delete/update with subqueries on joins [Kyle Bock](https://github.com/kwbock)
|
7
|
+
|
8
|
+
|
3
9
|
## 0.8.0 2017-08-16
|
4
10
|
|
5
11
|
* Significant improvements and simplifications of query rewriting
|
data/Gemfile.lock
CHANGED
data/docker-compose.yml
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
-
version: '2'
|
1
|
+
version: '2.1'
|
2
2
|
|
3
3
|
services:
|
4
4
|
master:
|
5
|
-
image: 'citusdata/citus:
|
5
|
+
image: 'citusdata/citus:7.0.1'
|
6
6
|
ports: ['5600:5432']
|
7
7
|
labels: ['com.citusdata.role=Master']
|
8
8
|
volumes: ['/var/run/postgresql']
|
9
9
|
worker1:
|
10
|
-
image: 'citusdata/citus:
|
10
|
+
image: 'citusdata/citus:7.0.1'
|
11
11
|
labels: ['com.citusdata.role=Worker']
|
12
|
+
depends_on: { manager: { condition: service_healthy } }
|
12
13
|
worker2:
|
13
|
-
image: 'citusdata/citus:
|
14
|
+
image: 'citusdata/citus:7.0.1'
|
14
15
|
labels: ['com.citusdata.role=Worker']
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
depends_on: { manager: { condition: service_healthy } }
|
17
|
+
manager:
|
18
|
+
container_name: "${COMPOSE_PROJECT_NAME:-citus}_manager"
|
19
|
+
image: 'citusdata/membership-manager:0.1.0'
|
20
|
+
volumes: ['/var/run/docker.sock:/var/run/docker.sock']
|
21
|
+
depends_on: { master: { condition: service_healthy } }
|
@@ -75,7 +75,7 @@ module MultiTenant
|
|
75
75
|
if o.left.is_a?(Arel::Attributes::Attribute)
|
76
76
|
table_name = o.left.relation.table_name
|
77
77
|
model = MultiTenant.multi_tenant_model_for_table(table_name)
|
78
|
-
@current_context.visited_handled_relation(o.left.relation) if model.present? && o.left.name == model.partition_key
|
78
|
+
@current_context.visited_handled_relation(o.left.relation) if model.present? && o.left.name.to_s == model.partition_key.to_s
|
79
79
|
end
|
80
80
|
super(o, *args)
|
81
81
|
end
|
@@ -184,8 +184,31 @@ module MultiTenant
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
end
|
187
|
+
|
188
|
+
module DatabaseStatements
|
189
|
+
def join_to_update(update, *args)
|
190
|
+
update = super(update, *args)
|
191
|
+
model = MultiTenant.multi_tenant_model_for_table(update.ast.relation.table_name)
|
192
|
+
if model.present?
|
193
|
+
update.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
|
194
|
+
end
|
195
|
+
update
|
196
|
+
end
|
197
|
+
|
198
|
+
def join_to_delete(delete, *args)
|
199
|
+
delete = super(delete, *args)
|
200
|
+
model = MultiTenant.multi_tenant_model_for_table(delete.ast.left.table_name)
|
201
|
+
if model.present?
|
202
|
+
delete.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
|
203
|
+
end
|
204
|
+
delete
|
205
|
+
end
|
206
|
+
end
|
187
207
|
end
|
188
208
|
|
209
|
+
require 'active_record/connection_adapters/abstract_adapter'
|
210
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(MultiTenant::DatabaseStatements)
|
211
|
+
|
189
212
|
Arel::Visitors::ToSql.include(MultiTenant::TenantValueVisitor)
|
190
213
|
|
191
214
|
require 'active_record/relation'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Query Rewriter" do
|
4
|
+
|
5
|
+
context "when bulk updating" do
|
6
|
+
let!(:account) { Account.create!(name: "Test Account") }
|
7
|
+
let!(:project) { Project.create(name: "Project 1", account: account) }
|
8
|
+
let!(:manager) { Manager.create(name: "Manager", project: project, account: account) }
|
9
|
+
|
10
|
+
it "updates the records" do
|
11
|
+
expect {
|
12
|
+
MultiTenant.with(account) do
|
13
|
+
Project.joins(:manager).update_all(name: "New Name")
|
14
|
+
end
|
15
|
+
}.to change { project.reload.name }.from("Project 1").to("New Name")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when bulk deleting" do
|
20
|
+
let!(:account) { Account.create!(name: "Test Account") }
|
21
|
+
let!(:project) { Project.create(name: "Project 1", account: account) }
|
22
|
+
let!(:manager) { Manager.create(name: "Manager", project: project, account: account) }
|
23
|
+
|
24
|
+
it "deletes the records" do
|
25
|
+
expect {
|
26
|
+
MultiTenant.with(account) do
|
27
|
+
Project.joins(:manager).delete_all
|
28
|
+
end
|
29
|
+
}.to change { Project.count }.from(1).to(0)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Citus Data
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: request_store
|
@@ -194,6 +194,7 @@ files:
|
|
194
194
|
- spec/activerecord-multi-tenant/controller_extensions_spec.rb
|
195
195
|
- spec/activerecord-multi-tenant/fast_truncate_spec.rb
|
196
196
|
- spec/activerecord-multi-tenant/model_extensions_spec.rb
|
197
|
+
- spec/activerecord-multi-tenant/query_rewriter_spec.rb
|
197
198
|
- spec/activerecord-multi-tenant/record_callback_spec.rb
|
198
199
|
- spec/activerecord-multi-tenant/record_finding_spec.rb
|
199
200
|
- spec/activerecord-multi-tenant/record_modifications_spec.rb
|