mongoid-multitenancy 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -1
- data/README.md +9 -6
- data/gemfiles/Gemfile.mongoid-6 +1 -1
- data/gemfiles/Gemfile.mongoid-7 +1 -1
- data/gemfiles/Gemfile.mongoid-8 +14 -0
- data/gemfiles/Gemfile.mongoid-9 +14 -0
- data/lib/mongoid/multitenancy/document.rb +4 -2
- data/lib/mongoid/multitenancy/version.rb +1 -1
- data/mongoid-multitenancy.gemspec +1 -1
- data/spec/indexable_spec.rb +49 -14
- data/spec/models/indexable.rb +53 -2
- data/spec/spec_helper.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6b73b7aa6b228218cdc8f7984b1e1b6ba340f06f23ad4730e533c7eda4fe9023
|
4
|
+
data.tar.gz: bf9b89578b7afef058724f6e3170b5158590894d6267d419df9675c1fa786e08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59a416b22144c02a3617356317421b27b6bb73947556c96c34ce36e67525d2b6a84a15bc5cd9f66d0acd9efd93e88cccaa1273c1dd4d3e6a08651acd294f5777
|
7
|
+
data.tar.gz: 3eefea63c163088fd87870cbe58d04aa8f17df612da993c552f666d01ebb4d9bf520715735f1afc04a234fba7a25573ba3e06b37bbc2c6c95951e8f4370da579
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [2.0.4] - 2024-06-17
|
8
|
+
### Fixed
|
9
|
+
|
10
|
+
* Full Support of mongoid 8 & 9
|
11
|
+
|
7
12
|
## [2.0.3] - 2020-06-25
|
8
13
|
### Fixed
|
9
14
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -15,7 +15,7 @@ In addition, mongoid-multitenancy:
|
|
15
15
|
Compatibility
|
16
16
|
===============
|
17
17
|
|
18
|
-
mongoid-multitenancy 2
|
18
|
+
mongoid-multitenancy 2 is compatible with mongoid 6/7/8/9. For mongoid 4/5 compatiblity, use mongoid-multitenancy 1.2.
|
19
19
|
|
20
20
|
Installation
|
21
21
|
===============
|
@@ -229,13 +229,13 @@ end
|
|
229
229
|
Mongoid indexes
|
230
230
|
-------------------
|
231
231
|
|
232
|
-
mongoid-multitenancy automatically adds the tenant foreign key in all your mongoid indexes to avoid to redefine all your validators. If you prefer to define
|
232
|
+
mongoid-multitenancy automatically adds the tenant foreign key in all your mongoid indexes to avoid to redefine all your validators. If you prefer to define the indexes manually, you can use the option `full_indexes: false` on the tenant or `full_index: true/false` on the indexes.
|
233
233
|
|
234
234
|
To create a single index on the tenant field, you can use the option `index: true` like any `belongs_to` declaration (false by default)
|
235
235
|
|
236
|
-
On the example below, only one
|
236
|
+
On the example below, only one index will be created:
|
237
237
|
|
238
|
-
* { '
|
238
|
+
* { 'tenant_id' => 1, 'title' => 1 }
|
239
239
|
|
240
240
|
```ruby
|
241
241
|
class Article
|
@@ -250,10 +250,11 @@ class Article
|
|
250
250
|
end
|
251
251
|
```
|
252
252
|
|
253
|
-
On the example below,
|
253
|
+
On the example below, 3 indexes will be created:
|
254
254
|
|
255
255
|
* { 'tenant_id' => 1 }
|
256
|
-
* { '
|
256
|
+
* { 'tenant_id' => 1, 'title' => 1 }
|
257
|
+
* { 'name' => 1 }
|
257
258
|
|
258
259
|
```ruby
|
259
260
|
class Article
|
@@ -263,8 +264,10 @@ class Article
|
|
263
264
|
tenant :tenant, index: true
|
264
265
|
|
265
266
|
field :title
|
267
|
+
field :name
|
266
268
|
|
267
269
|
index({ :title => 1 })
|
270
|
+
index({ :name => 1 }, { full_index: false })
|
268
271
|
end
|
269
272
|
```
|
270
273
|
|
data/gemfiles/Gemfile.mongoid-6
CHANGED
data/gemfiles/Gemfile.mongoid-7
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'mongoid', '~> 8.0'
|
4
|
+
|
5
|
+
gem 'rake'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'database_cleaner-mongoid'
|
9
|
+
gem 'coveralls', require: false
|
10
|
+
gem 'rspec', '~> 3.1'
|
11
|
+
gem 'yard'
|
12
|
+
gem 'mongoid-rspec', git: 'https://github.com/mongoid-rspec/mongoid-rspec.git'
|
13
|
+
gem 'rubocop', require: false
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'mongoid', '~> 9.0'
|
4
|
+
|
5
|
+
gem 'rake'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'database_cleaner-mongoid'
|
9
|
+
gem 'coveralls', require: false
|
10
|
+
gem 'rspec', '~> 3.1'
|
11
|
+
gem 'yard'
|
12
|
+
gem 'mongoid-rspec', git: 'https://github.com/mongoid-rspec/mongoid-rspec.git'
|
13
|
+
gem 'rubocop', require: false
|
14
|
+
end
|
@@ -87,11 +87,13 @@ module Mongoid
|
|
87
87
|
|
88
88
|
# Redefine 'index' to include the tenant field in first position
|
89
89
|
def index(spec, options = nil)
|
90
|
-
|
90
|
+
super_options = (options || {}).dup
|
91
|
+
full_index = super_options.delete(:full_index)
|
92
|
+
if full_index.nil? ? tenant_options[:full_indexes] : full_index
|
91
93
|
spec = { tenant_field => 1 }.merge(spec)
|
92
94
|
end
|
93
95
|
|
94
|
-
super(spec,
|
96
|
+
super(spec, super_options)
|
95
97
|
end
|
96
98
|
|
97
99
|
# Redefine 'delete_all' to take in account the default scope
|
data/spec/indexable_spec.rb
CHANGED
@@ -9,27 +9,62 @@ describe 'tenant' do
|
|
9
9
|
Mongoid::Multitenancy.current_tenant = client
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
describe 'tenant full_indexes option' do
|
13
|
+
context 'without index option' do
|
14
|
+
it 'does not create an index' do
|
15
|
+
expect(IndexableWithoutIndex).not_to have_index_for(tenant_id: 1)
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
context 'with index: false' do
|
20
|
+
it 'does not create an index' do
|
21
|
+
expect(IndexableWithIndexFalse).not_to have_index_for(tenant_id: 1)
|
22
|
+
end
|
21
23
|
end
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
context 'with index: true' do
|
26
|
+
it 'creates an index' do
|
27
|
+
expect(IndexableWithIndexTrue).to have_index_for(tenant_id: 1)
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
describe 'index full_index option' do
|
33
|
+
context 'without tenant full_indexes option specified' do
|
34
|
+
it 'adds the tenant field on each index' do
|
35
|
+
expect(IndexableWithoutFullIndexes).to have_index_for(tenant_id: 1, title: 1)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'adds the tenant field on the index with full_index: true' do
|
39
|
+
expect(IndexableWithoutFullIndexes).to have_index_for(tenant_id: 1, name: 1)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'does not add the tenant field on the index with full_index: false' do
|
43
|
+
expect(IndexableWithoutFullIndexes).not_to have_index_for(tenant_id: 1, slug: 1)
|
44
|
+
expect(IndexableWithoutFullIndexes).to have_index_for(slug: 1)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with full_indexes: true' do
|
49
|
+
it 'adds the tenant field on each index' do
|
50
|
+
expect(IndexableWithFullIndexesTrue).to have_index_for(tenant_id: 1, title: 1)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'does not add the tenant field on the index with full_index: false' do
|
54
|
+
expect(IndexableWithFullIndexesTrue).not_to have_index_for(tenant_id: 1, name: 1)
|
55
|
+
expect(IndexableWithFullIndexesTrue).to have_index_for(name: 1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with full_indexes: false' do
|
60
|
+
it 'does not add the tenant field on each index' do
|
61
|
+
expect(IndexableWithFullIndexesFalse).not_to have_index_for(tenant_id: 1, title: 1)
|
62
|
+
expect(IndexableWithFullIndexesFalse).to have_index_for(title: 1)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'does add the tenant field on the index with full_index: true' do
|
66
|
+
expect(IndexableWithFullIndexesFalse).to have_index_for(tenant_id: 1, name: 1)
|
67
|
+
end
|
33
68
|
end
|
34
69
|
end
|
35
70
|
end
|
data/spec/models/indexable.rb
CHANGED
@@ -1,10 +1,61 @@
|
|
1
|
-
class
|
1
|
+
class IndexableWithoutIndex
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Multitenancy::Document
|
4
|
+
|
5
|
+
tenant :tenant, class_name: 'Account'
|
6
|
+
end
|
7
|
+
|
8
|
+
class IndexableWithIndexTrue
|
9
|
+
include Mongoid::Document
|
10
|
+
include Mongoid::Multitenancy::Document
|
11
|
+
|
12
|
+
tenant :tenant, class_name: 'Account', index: true
|
13
|
+
end
|
14
|
+
|
15
|
+
class IndexableWithIndexFalse
|
16
|
+
include Mongoid::Document
|
17
|
+
include Mongoid::Multitenancy::Document
|
18
|
+
|
19
|
+
tenant :tenant, class_name: 'Account', index: false
|
20
|
+
end
|
21
|
+
|
22
|
+
class IndexableWithoutFullIndexes
|
23
|
+
include Mongoid::Document
|
24
|
+
include Mongoid::Multitenancy::Document
|
25
|
+
|
26
|
+
field :title, type: String
|
27
|
+
field :name, type: String
|
28
|
+
field :slug, type: String
|
29
|
+
|
30
|
+
tenant :tenant, class_name: 'Account'
|
31
|
+
|
32
|
+
index(title: 1)
|
33
|
+
index({ name: 1 }, { full_index: true })
|
34
|
+
index({ slug: 1 }, { full_index: false })
|
35
|
+
end
|
36
|
+
|
37
|
+
class IndexableWithFullIndexesFalse
|
38
|
+
include Mongoid::Document
|
39
|
+
include Mongoid::Multitenancy::Document
|
40
|
+
|
41
|
+
field :title, type: String
|
42
|
+
field :name, type: String
|
43
|
+
|
44
|
+
tenant :tenant, class_name: 'Account', full_indexes: false
|
45
|
+
|
46
|
+
index(title: 1)
|
47
|
+
index({ name: 1 }, { full_index: true })
|
48
|
+
end
|
49
|
+
|
50
|
+
class IndexableWithFullIndexesTrue
|
2
51
|
include Mongoid::Document
|
3
52
|
include Mongoid::Multitenancy::Document
|
4
53
|
|
5
54
|
field :title, type: String
|
55
|
+
field :name, type: String
|
6
56
|
|
7
|
-
tenant :tenant, class_name: 'Account',
|
57
|
+
tenant :tenant, class_name: 'Account', full_indexes: true
|
8
58
|
|
9
59
|
index(title: 1)
|
60
|
+
index({ name: 1 }, { full_index: false })
|
10
61
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-multitenancy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aymeric Brisse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '6'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '10'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '6'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '10'
|
33
33
|
description: MultiTenancy with Mongoid
|
34
34
|
email:
|
35
35
|
- aymeric.brisse@mperfect-memory.com
|
@@ -47,6 +47,8 @@ files:
|
|
47
47
|
- Rakefile
|
48
48
|
- gemfiles/Gemfile.mongoid-6
|
49
49
|
- gemfiles/Gemfile.mongoid-7
|
50
|
+
- gemfiles/Gemfile.mongoid-8
|
51
|
+
- gemfiles/Gemfile.mongoid-9
|
50
52
|
- lib/mongoid-multitenancy.rb
|
51
53
|
- lib/mongoid/multitenancy.rb
|
52
54
|
- lib/mongoid/multitenancy/document.rb
|
@@ -95,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
97
|
- !ruby/object:Gem::Version
|
96
98
|
version: '0'
|
97
99
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.6.14.4
|
100
|
+
rubygems_version: 3.3.27
|
100
101
|
signing_key:
|
101
102
|
specification_version: 4
|
102
103
|
summary: Support of a multi-tenant database with Mongoid
|