activerecord-multi-tenant 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/activerecord-multi-tenant/migrations.rb +7 -1
- data/lib/activerecord-multi-tenant/multi_tenant.rb +26 -8
- data/lib/activerecord-multi-tenant/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eac7c3d60913d1596d061cdca9fca210c2f5e44eb87c60fe55a65f05161840fa
|
4
|
+
data.tar.gz: b183e17a1effb9ad711e784a4ae82be5eb209b8b6d84993cfe4ea5db5c2fe800
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3892fefdeb8636a7ceb80d5538cf49c73f7baf9957226f59156b8cfdceacd92760392aba0eee8232f17a9604eed1b502b9257c0df0614882e2d948afb64398ce
|
7
|
+
data.tar.gz: b79eb29f19b1b5c2f3320fc3b79bc6fc8baa64a5217059a093e6fce77884280a9f9f67be2d1f842e620addfa61711704a63052c8b75c2ad3de68cd3c4e7a8407
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.1.4 2022-11-03
|
4
|
+
* Fixes #166 where db:schema:dump is broken when using this gem with MySQL [#167](https://github.com/citusdata/activerecord-multi-tenant/pull/167)
|
5
|
+
|
6
|
+
## 2.1.3 2022-10-27
|
7
|
+
* Error when calling a method that takes keyword arguments with MultiTenant.wrap_methods [#164](https://github.com/citusdata/activerecord-multi-tenant/pull/164)
|
8
|
+
|
3
9
|
## 2.1.2 2022-10-26
|
4
10
|
* Fixes issue when wraping methods that require a block [#162](https://github.com/citusdata/activerecord-multi-tenant/pull/162)
|
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
|
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
|
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
|
@@ -110,19 +110,37 @@ module MultiTenant
|
|
110
110
|
end
|
111
111
|
|
112
112
|
# Wrap calls to any of `method_names` on an instance Class `klass` with MultiTenant.with when `'owner'` (evaluated in context of the klass instance) is a ActiveRecord model instance that is multi-tenant
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
if Gem::Version.create(RUBY_VERSION) < Gem::Version.new("2.7.0")
|
114
|
+
def self.wrap_methods(klass, owner, *method_names)
|
115
|
+
method_names.each do |method_name|
|
116
|
+
original_method_name = :"_mt_original_#{method_name}"
|
117
|
+
klass.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
118
|
+
alias_method :#{original_method_name}, :#{method_name}
|
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?
|
121
|
+
MultiTenant.with(#{owner}.public_send(#{owner}.class.partition_key)) { #{original_method_name}(*args, &block) }
|
122
|
+
else
|
123
|
+
#{original_method_name}(*args, &block)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
CODE
|
127
|
+
end
|
128
|
+
end
|
129
|
+
else
|
130
|
+
def self.wrap_methods(klass, owner, *method_names)
|
131
|
+
method_names.each do |method_name|
|
132
|
+
original_method_name = :"_mt_original_#{method_name}"
|
133
|
+
klass.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
117
134
|
alias_method :#{original_method_name}, :#{method_name}
|
118
|
-
def #{method_name}(
|
135
|
+
def #{method_name}(...)
|
119
136
|
if MultiTenant.multi_tenant_model_for_table(#{owner}.class.table_name).present? && #{owner}.persisted? && MultiTenant.current_tenant_id.nil?
|
120
|
-
MultiTenant.with(#{owner}.public_send(#{owner}.class.partition_key)) { #{original_method_name}(
|
137
|
+
MultiTenant.with(#{owner}.public_send(#{owner}.class.partition_key)) { #{original_method_name}(...) }
|
121
138
|
else
|
122
|
-
#{original_method_name}(
|
139
|
+
#{original_method_name}(...)
|
123
140
|
end
|
124
141
|
end
|
125
|
-
|
142
|
+
CODE
|
143
|
+
end
|
126
144
|
end
|
127
145
|
end
|
128
146
|
|
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.
|
4
|
+
version: 2.1.4
|
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
|
+
date: 2022-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|