activerecord-multi-tenant 2.1.2 → 2.1.4

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: 6da68db2d8d58cc00bc0fd9de50b85544fff943596c4ed7fb9211380419e1b1b
4
- data.tar.gz: a5126bdd3b733a6e58c0c5d1e63e7bfe27b76a18fd790219ee08641379019336
3
+ metadata.gz: eac7c3d60913d1596d061cdca9fca210c2f5e44eb87c60fe55a65f05161840fa
4
+ data.tar.gz: b183e17a1effb9ad711e784a4ae82be5eb209b8b6d84993cfe4ea5db5c2fe800
5
5
  SHA512:
6
- metadata.gz: 69be1d704a41ee78b28c9f23cb8bb1f606a97146c979ca087eeef1d43fa4a482bacedc21317677862f427567d98abcc4199f029eb04719b2dab363bb29a2160d
7
- data.tar.gz: a6495adf22bbd72f03e15f8056e57c9dbabfaab9dde1b15fc3365794a1a8c25f624e094e82de2b7ed1648dcad990b410b6f3b97e6369534aa7ea6ee528505360
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 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
@@ -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
- def self.wrap_methods(klass, owner, *method_names)
114
- method_names.each do |method_name|
115
- original_method_name = :"_mt_original_#{method_name}"
116
- klass.class_eval <<-CODE, __FILE__, __LINE__ + 1
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}(*args, &block)
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}(*args, &block) }
137
+ MultiTenant.with(#{owner}.public_send(#{owner}.class.partition_key)) { #{original_method_name}(...) }
121
138
  else
122
- #{original_method_name}(*args, &block)
139
+ #{original_method_name}(...)
123
140
  end
124
141
  end
125
- CODE
142
+ CODE
143
+ end
126
144
  end
127
145
  end
128
146
 
@@ -1,3 +1,3 @@
1
1
  module MultiTenant
2
- VERSION = '2.1.2'
2
+ VERSION = '2.1.4'
3
3
  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: 2.1.2
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-10-26 00:00:00.000000000 Z
11
+ date: 2022-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails