update_values_all 1.1.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 407100066be1214e75c13c733db1fcb66ab8eae08a73d5edaf28b9fe805a54af
4
- data.tar.gz: 4a0cb4a3f0aa7e4b9c6154ad760fe53a486b96ab96e46502f9ac4daeed6d3150
3
+ metadata.gz: f71e64cbaa8a9deadadfcc8ee812e3625e955eeff998b55871bf1bde85c66a6c
4
+ data.tar.gz: dfbff95794c8ad1ce0c7b9231baa132a695599cc3351ed0c31b6961b0a1e4ec1
5
5
  SHA512:
6
- metadata.gz: b31196412dcf1f69187a979c0bde27e60262d0683ba0967be698a7768f187452720099fda52253a954539d71668879d9c7d712735af7731aa8f414ab8dbdd07a
7
- data.tar.gz: 97f917b319a95a738fcf7d2e510a86e7b1a6e1b92fcbfbba210498e90391cb0992ba8479add5302302c52c3c10d341b5824018326a31617418c729006a25d49f
6
+ metadata.gz: 3423fdcaa0d005e2abc4af2eb8d0645a77aebc6e423b70ba316e5bba7a4c49f1f1a7db200e8bad00e3b688a34df0b8c4b6001f6e550881f10ba9d00e8fca6260
7
+ data.tar.gz: c79f7b4bc6e0e60b74557ea53cc4fbec6f576af63f2d42dde2ace760c7f2098dda162ca3860848dda119be33a06f4e0561555555d70b9e89e3b4962aa0dd3d98
data/.rubocop.yml CHANGED
@@ -3,4 +3,7 @@ inherit_gem:
3
3
  - ./config/default.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.7
6
+ TargetRubyVersion: 3.1
7
+
8
+ Gp/OptArgParameters:
9
+ Enabled: false
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise "activerecord-6.1" do
2
+ gem "activerecord", "~> 6.1"
3
+ end
4
+
5
+ appraise "activerecord-7.1" do
6
+ gem "activerecord", ">= 7.1"
7
+ end
data/Gemfile.lock CHANGED
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: https://github.com/corp-gp/rubocop-gp.git
3
- revision: e5bd900ce4b10077cf8f4ae88a5a6e32e7861b65
3
+ revision: 1039b83ebd2f8334df6175d410f9a1b025d97384
4
4
  specs:
5
5
  rubocop-gp (0.0.4)
6
6
  rubocop
@@ -14,153 +14,221 @@ GIT
14
14
  PATH
15
15
  remote: .
16
16
  specs:
17
- update_values_all (1.0.2)
18
- activerecord (>= 4.2)
17
+ update_values_all (1.1.0)
19
18
 
20
19
  GEM
21
20
  remote: https://rubygems.org/
22
21
  specs:
23
- actionpack (7.0.4.3)
24
- actionview (= 7.0.4.3)
25
- activesupport (= 7.0.4.3)
26
- rack (~> 2.0, >= 2.2.0)
22
+ actionpack (7.2.2.1)
23
+ actionview (= 7.2.2.1)
24
+ activesupport (= 7.2.2.1)
25
+ nokogiri (>= 1.8.5)
26
+ racc
27
+ rack (>= 2.2.4, < 3.2)
28
+ rack-session (>= 1.0.1)
27
29
  rack-test (>= 0.6.3)
28
- rails-dom-testing (~> 2.0)
29
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
30
- actionview (7.0.4.3)
31
- activesupport (= 7.0.4.3)
30
+ rails-dom-testing (~> 2.2)
31
+ rails-html-sanitizer (~> 1.6)
32
+ useragent (~> 0.16)
33
+ actionview (7.2.2.1)
34
+ activesupport (= 7.2.2.1)
32
35
  builder (~> 3.1)
33
- erubi (~> 1.4)
34
- rails-dom-testing (~> 2.0)
35
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
36
- activemodel (7.0.4.3)
37
- activesupport (= 7.0.4.3)
38
- activerecord (7.0.4.3)
39
- activemodel (= 7.0.4.3)
40
- activesupport (= 7.0.4.3)
41
- activesupport (7.0.4.3)
42
- concurrent-ruby (~> 1.0, >= 1.0.2)
36
+ erubi (~> 1.11)
37
+ rails-dom-testing (~> 2.2)
38
+ rails-html-sanitizer (~> 1.6)
39
+ activesupport (7.2.2.1)
40
+ base64
41
+ benchmark (>= 0.3)
42
+ bigdecimal
43
+ concurrent-ruby (~> 1.0, >= 1.3.1)
44
+ connection_pool (>= 2.2.5)
45
+ drb
43
46
  i18n (>= 1.6, < 2)
47
+ logger (>= 1.4.2)
44
48
  minitest (>= 5.1)
45
- tzinfo (~> 2.0)
46
- ast (2.4.2)
47
- builder (3.2.4)
48
- combustion (1.3.7)
49
+ securerandom (>= 0.3)
50
+ tzinfo (~> 2.0, >= 2.0.5)
51
+ appraisal (2.5.0)
52
+ bundler
53
+ rake
54
+ thor (>= 0.14.0)
55
+ ast (2.4.3)
56
+ base64 (0.2.0)
57
+ benchmark (0.4.0)
58
+ bigdecimal (3.1.9)
59
+ builder (3.3.0)
60
+ combustion (1.5.0)
49
61
  activesupport (>= 3.0.0)
50
62
  railties (>= 3.0.0)
51
63
  thor (>= 0.14.6)
52
- concurrent-ruby (1.3.4)
64
+ concurrent-ruby (1.3.5)
65
+ connection_pool (2.5.0)
53
66
  crass (1.0.6)
54
- diff-lcs (1.5.0)
55
- dotenv (2.8.1)
56
- dotenv-rails (2.8.1)
57
- dotenv (= 2.8.1)
58
- railties (>= 3.2)
59
- erubi (1.12.0)
60
- i18n (1.14.5)
67
+ date (3.4.1)
68
+ diff-lcs (1.6.1)
69
+ dotenv (3.1.7)
70
+ dotenv-rails (3.1.7)
71
+ dotenv (= 3.1.7)
72
+ railties (>= 6.1)
73
+ drb (2.2.1)
74
+ erubi (1.13.1)
75
+ i18n (1.14.7)
61
76
  concurrent-ruby (~> 1.0)
62
- json (2.7.2)
63
- language_server-protocol (3.17.0.3)
64
- lefthook (1.3.8)
65
- loofah (2.19.1)
77
+ io-console (0.8.0)
78
+ irb (1.15.2)
79
+ pp (>= 0.6.0)
80
+ rdoc (>= 4.0.0)
81
+ reline (>= 0.4.2)
82
+ json (2.10.2)
83
+ language_server-protocol (3.17.0.4)
84
+ lefthook (1.11.8)
85
+ lint_roller (1.1.0)
86
+ logger (1.7.0)
87
+ loofah (2.24.0)
66
88
  crass (~> 1.0.2)
67
- nokogiri (>= 1.5.9)
68
- method_source (1.0.0)
69
- minitest (5.25.1)
70
- nokogiri (1.16.7-arm64-darwin)
89
+ nokogiri (>= 1.12.0)
90
+ minitest (5.25.5)
91
+ nokogiri (1.18.7-aarch64-linux-gnu)
92
+ racc (~> 1.4)
93
+ nokogiri (1.18.7-aarch64-linux-musl)
94
+ racc (~> 1.4)
95
+ nokogiri (1.18.7-arm-linux-gnu)
96
+ racc (~> 1.4)
97
+ nokogiri (1.18.7-arm-linux-musl)
71
98
  racc (~> 1.4)
72
- nokogiri (1.16.7-x86_64-linux)
99
+ nokogiri (1.18.7-arm64-darwin)
100
+ racc (~> 1.4)
101
+ nokogiri (1.18.7-x86_64-darwin)
102
+ racc (~> 1.4)
103
+ nokogiri (1.18.7-x86_64-linux-gnu)
104
+ racc (~> 1.4)
105
+ nokogiri (1.18.7-x86_64-linux-musl)
73
106
  racc (~> 1.4)
74
107
  parallel (1.26.3)
75
- parser (3.3.4.2)
108
+ parser (3.3.7.4)
76
109
  ast (~> 2.4.1)
77
110
  racc
78
- pg (1.4.6)
111
+ pg (1.5.9)
112
+ pp (0.6.2)
113
+ prettyprint
114
+ prettyprint (0.2.0)
115
+ prism (1.4.0)
116
+ psych (5.2.3)
117
+ date
118
+ stringio
79
119
  racc (1.8.1)
80
- rack (2.2.9)
81
- rack-test (2.1.0)
120
+ rack (3.1.12)
121
+ rack-session (2.1.0)
122
+ base64 (>= 0.1.0)
123
+ rack (>= 3.0.0)
124
+ rack-test (2.2.0)
82
125
  rack (>= 1.3)
83
- rails-dom-testing (2.0.3)
84
- activesupport (>= 4.2.0)
126
+ rackup (2.2.1)
127
+ rack (>= 3)
128
+ rails-dom-testing (2.2.0)
129
+ activesupport (>= 5.0.0)
130
+ minitest
85
131
  nokogiri (>= 1.6)
86
- rails-html-sanitizer (1.5.0)
87
- loofah (~> 2.19, >= 2.19.1)
88
- railties (7.0.4.3)
89
- actionpack (= 7.0.4.3)
90
- activesupport (= 7.0.4.3)
91
- method_source
132
+ rails-html-sanitizer (1.6.2)
133
+ loofah (~> 2.21)
134
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
135
+ railties (7.2.2.1)
136
+ actionpack (= 7.2.2.1)
137
+ activesupport (= 7.2.2.1)
138
+ irb (~> 1.13)
139
+ rackup (>= 1.0.0)
92
140
  rake (>= 12.2)
93
- thor (~> 1.0)
94
- zeitwerk (~> 2.5)
141
+ thor (~> 1.0, >= 1.2.2)
142
+ zeitwerk (~> 2.6)
95
143
  rainbow (3.1.1)
96
- rake (13.0.6)
97
- regexp_parser (2.9.2)
98
- rexml (3.3.6)
99
- strscan
100
- rspec (3.11.0)
101
- rspec-core (~> 3.11.0)
102
- rspec-expectations (~> 3.11.0)
103
- rspec-mocks (~> 3.11.0)
104
- rspec-core (3.11.0)
105
- rspec-support (~> 3.11.0)
106
- rspec-expectations (3.11.0)
144
+ rake (13.2.1)
145
+ rdoc (6.13.1)
146
+ psych (>= 4.0.0)
147
+ regexp_parser (2.10.0)
148
+ reline (0.6.1)
149
+ io-console (~> 0.5)
150
+ rspec (3.13.0)
151
+ rspec-core (~> 3.13.0)
152
+ rspec-expectations (~> 3.13.0)
153
+ rspec-mocks (~> 3.13.0)
154
+ rspec-core (3.13.3)
155
+ rspec-support (~> 3.13.0)
156
+ rspec-expectations (3.13.3)
107
157
  diff-lcs (>= 1.2.0, < 2.0)
108
- rspec-support (~> 3.11.0)
109
- rspec-mocks (3.11.1)
158
+ rspec-support (~> 3.13.0)
159
+ rspec-mocks (3.13.2)
110
160
  diff-lcs (>= 1.2.0, < 2.0)
111
- rspec-support (~> 3.11.0)
112
- rspec-rails (6.0.1)
113
- actionpack (>= 6.1)
114
- activesupport (>= 6.1)
115
- railties (>= 6.1)
116
- rspec-core (~> 3.11)
117
- rspec-expectations (~> 3.11)
118
- rspec-mocks (~> 3.11)
119
- rspec-support (~> 3.11)
120
- rspec-support (3.11.0)
121
- rubocop (1.65.1)
161
+ rspec-support (~> 3.13.0)
162
+ rspec-rails (7.1.1)
163
+ actionpack (>= 7.0)
164
+ activesupport (>= 7.0)
165
+ railties (>= 7.0)
166
+ rspec-core (~> 3.13)
167
+ rspec-expectations (~> 3.13)
168
+ rspec-mocks (~> 3.13)
169
+ rspec-support (~> 3.13)
170
+ rspec-support (3.13.2)
171
+ rubocop (1.75.2)
122
172
  json (~> 2.3)
123
- language_server-protocol (>= 3.17.0)
173
+ language_server-protocol (~> 3.17.0.2)
174
+ lint_roller (~> 1.1.0)
124
175
  parallel (~> 1.10)
125
176
  parser (>= 3.3.0.2)
126
177
  rainbow (>= 2.2.2, < 4.0)
127
- regexp_parser (>= 2.4, < 3.0)
128
- rexml (>= 3.2.5, < 4.0)
129
- rubocop-ast (>= 1.31.1, < 2.0)
178
+ regexp_parser (>= 2.9.3, < 3.0)
179
+ rubocop-ast (>= 1.44.0, < 2.0)
130
180
  ruby-progressbar (~> 1.7)
131
- unicode-display_width (>= 2.4.0, < 3.0)
132
- rubocop-ast (1.32.1)
133
- parser (>= 3.3.1.0)
134
- rubocop-capybara (2.21.0)
135
- rubocop (~> 1.41)
136
- rubocop-factory_bot (2.26.1)
137
- rubocop (~> 1.61)
138
- rubocop-performance (1.21.1)
139
- rubocop (>= 1.48.1, < 2.0)
140
- rubocop-ast (>= 1.31.1, < 2.0)
141
- rubocop-rails (2.26.0)
181
+ unicode-display_width (>= 2.4.0, < 4.0)
182
+ rubocop-ast (1.44.0)
183
+ parser (>= 3.3.7.2)
184
+ prism (~> 1.4)
185
+ rubocop-capybara (2.22.1)
186
+ lint_roller (~> 1.1)
187
+ rubocop (~> 1.72, >= 1.72.1)
188
+ rubocop-factory_bot (2.27.1)
189
+ lint_roller (~> 1.1)
190
+ rubocop (~> 1.72, >= 1.72.1)
191
+ rubocop-performance (1.25.0)
192
+ lint_roller (~> 1.1)
193
+ rubocop (>= 1.75.0, < 2.0)
194
+ rubocop-ast (>= 1.38.0, < 2.0)
195
+ rubocop-rails (2.31.0)
142
196
  activesupport (>= 4.2.0)
197
+ lint_roller (~> 1.1)
143
198
  rack (>= 1.1)
144
- rubocop (>= 1.52.0, < 2.0)
145
- rubocop-ast (>= 1.31.1, < 2.0)
146
- rubocop-rspec (3.0.4)
147
- rubocop (~> 1.61)
148
- rubocop-rspec_rails (2.30.0)
149
- rubocop (~> 1.61)
150
- rubocop-rspec (~> 3, >= 3.0.1)
199
+ rubocop (>= 1.75.0, < 2.0)
200
+ rubocop-ast (>= 1.38.0, < 2.0)
201
+ rubocop-rspec (3.5.0)
202
+ lint_roller (~> 1.1)
203
+ rubocop (~> 1.72, >= 1.72.1)
204
+ rubocop-rspec_rails (2.31.0)
205
+ lint_roller (~> 1.1)
206
+ rubocop (~> 1.72, >= 1.72.1)
207
+ rubocop-rspec (~> 3.5)
151
208
  ruby-progressbar (1.13.0)
152
- strscan (3.1.0)
153
- thor (1.2.1)
209
+ securerandom (0.4.1)
210
+ stringio (3.1.6)
211
+ thor (1.3.2)
154
212
  tzinfo (2.0.6)
155
213
  concurrent-ruby (~> 1.0)
156
- unicode-display_width (2.5.0)
157
- zeitwerk (2.6.7)
214
+ unicode-display_width (3.1.4)
215
+ unicode-emoji (~> 4.0, >= 4.0.4)
216
+ unicode-emoji (4.0.4)
217
+ useragent (0.16.11)
218
+ zeitwerk (2.6.18)
158
219
 
159
220
  PLATFORMS
160
- arm64-darwin-23
161
- x86_64-linux
221
+ aarch64-linux-gnu
222
+ aarch64-linux-musl
223
+ arm-linux-gnu
224
+ arm-linux-musl
225
+ arm64-darwin
226
+ x86_64-darwin
227
+ x86_64-linux-gnu
228
+ x86_64-linux-musl
162
229
 
163
230
  DEPENDENCIES
231
+ appraisal
164
232
  combustion
165
233
  dotenv-rails
166
234
  lefthook
@@ -171,4 +239,4 @@ DEPENDENCIES
171
239
  update_values_all!
172
240
 
173
241
  BUNDLED WITH
174
- 2.4.6
242
+ 2.5.7
@@ -4,8 +4,9 @@ module UpdateValuesAll
4
4
  module Adapters
5
5
  module Postgres
6
6
 
7
- def pg_update_values_all(data, key_to_match:, touch: false, sql_update_expression: 'updated_at = CURRENT_TIMESTAMP')
7
+ def pg_update_values_all(data, key_to_match:, touch: false, sql_update_expression: "updated_at = CURRENT_TIMESTAMP")
8
8
  keys = data.first.keys
9
+ key_to_match = Array.wrap(key_to_match)
9
10
 
10
11
  sql_values = +''
11
12
  data.each do |hash_row|
@@ -23,26 +24,24 @@ module UpdateValuesAll
23
24
  end
24
25
  sql_values.chop!
25
26
 
26
- updated_keys = keys.join(', ')
27
+ updated_keys = keys.join(", ")
27
28
 
28
29
  sql_types = data[0].keys.index_with { |column_name| column_for_attribute(column_name).sql_type_metadata.sql_type }
29
30
  set_expr =
30
31
  if block_given?
31
32
  +yield
32
33
  else
33
- keys
34
- .reject { |key| key == key_to_match }
34
+ (keys - key_to_match)
35
35
  .map { |key| "#{key} = updated_data.#{key}::#{sql_types[key]}" }
36
- .join(', ')
36
+ .join(", ")
37
37
  end
38
38
  only_changed_expr =
39
39
  if touch
40
- 'TRUE'
40
+ "TRUE"
41
41
  else
42
- keys
43
- .reject { |key| key == key_to_match }
42
+ (keys - key_to_match)
44
43
  .map { |key| "#{table_name}.#{key} IS DISTINCT FROM updated_data.#{key}::#{sql_types[key]}" }
45
- .join(' OR ')
44
+ .join(" OR ")
46
45
  end
47
46
 
48
47
  if sql_update_expression.present?
@@ -50,12 +49,12 @@ module UpdateValuesAll
50
49
  end
51
50
 
52
51
  existing_data_sql =
53
- select("#{table_name}.#{key_to_match}") # rubocop:disable Gp/PotentialSqlInjection
54
- .where("#{key_to_match} IN (SELECT #{key_to_match} FROM updated_data)")
52
+ select(primary_keys_sql(key_to_match, table_name)) # rubocop:disable Gp/PotentialSqlInjection
53
+ .where("(#{primary_keys_sql(key_to_match, table_name)}) IN (SELECT #{primary_keys_sql(key_to_match, 'updated_data')} FROM updated_data)")
55
54
  .to_sql
56
55
 
57
56
  changed_ids =
58
- connection.query(<<~SQL).flatten # rubocop:disable Gp/PotentialSqlInjection
57
+ connection.query(<<~SQL) # rubocop:disable Gp/PotentialSqlInjection
59
58
  WITH
60
59
  updated_data(#{updated_keys}) AS (
61
60
  VALUES #{sql_values}
@@ -65,19 +64,23 @@ module UpdateValuesAll
65
64
  )
66
65
  UPDATE #{table_name}
67
66
  SET #{set_expr}
68
- FROM updated_data JOIN existing_data ON existing_data.#{key_to_match} = updated_data.#{key_to_match}
67
+ FROM updated_data JOIN existing_data ON (#{primary_keys_sql(key_to_match, 'existing_data')}) = (#{primary_keys_sql(key_to_match, 'updated_data')})
69
68
  WHERE
70
- updated_data.#{key_to_match} = #{table_name}.#{key_to_match}
71
- AND #{table_name}.#{key_to_match} = existing_data.#{key_to_match}
69
+ (#{primary_keys_sql(key_to_match, 'updated_data')}) = (#{primary_keys_sql(key_to_match, table_name)})
70
+ AND (#{primary_keys_sql(key_to_match, table_name)}) = (#{primary_keys_sql(key_to_match, 'existing_data')})
72
71
  AND (#{only_changed_expr})
73
- RETURNING #{table_name}.#{key_to_match}
72
+ RETURNING #{primary_keys_sql(key_to_match, table_name)}
74
73
  SQL
75
74
 
76
75
  connection.query_cache.clear if connection.query_cache_enabled
77
76
 
78
- changed_ids
77
+ # When the primary key is composite (multi-column), we return an array of arrays
78
+ key_to_match.size == 1 ? changed_ids.flatten : changed_ids
79
79
  end
80
80
 
81
+ private def primary_keys_sql(keys, table_name)
82
+ keys.map { |key| "#{table_name}.#{key}" }.join(", ")
83
+ end
81
84
  end
82
85
  end
83
86
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module UpdateValuesAll
4
4
 
5
- VERSION = '1.1.0'
5
+ VERSION = '1.2.0'
6
6
 
7
7
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: update_values_all
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Malykh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-11 00:00:00.000000000 Z
11
+ date: 2025-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activerecord
14
+ name: appraisal
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
20
- type: :runtime
19
+ version: '0'
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '0'
27
27
  description:
28
28
  email:
29
29
  - xronos.i.am@gmail.com
@@ -35,6 +35,7 @@ files:
35
35
  - ".env.sample"
36
36
  - ".rspec"
37
37
  - ".rubocop.yml"
38
+ - Appraisals
38
39
  - CHANGELOG.md
39
40
  - CODE_OF_CONDUCT.md
40
41
  - Gemfile
@@ -72,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
73
  - !ruby/object:Gem::Version
73
74
  version: '0'
74
75
  requirements: []
75
- rubygems_version: 3.3.17
76
+ rubygems_version: 3.3.7
76
77
  signing_key:
77
78
  specification_version: 4
78
79
  summary: The gem allows to update AR-records in batch