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 +4 -4
- data/.rubocop.yml +4 -1
- data/Appraisals +7 -0
- data/Gemfile.lock +177 -109
- data/lib/update_values_all/adapters/postgres.rb +20 -17
- data/lib/update_values_all/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f71e64cbaa8a9deadadfcc8ee812e3625e955eeff998b55871bf1bde85c66a6c
|
4
|
+
data.tar.gz: dfbff95794c8ad1ce0c7b9231baa132a695599cc3351ed0c31b6961b0a1e4ec1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3423fdcaa0d005e2abc4af2eb8d0645a77aebc6e423b70ba316e5bba7a4c49f1f1a7db200e8bad00e3b688a34df0b8c4b6001f6e550881f10ba9d00e8fca6260
|
7
|
+
data.tar.gz: c79f7b4bc6e0e60b74557ea53cc4fbec6f576af63f2d42dde2ace760c7f2098dda162ca3860848dda119be33a06f4e0561555555d70b9e89e3b4962aa0dd3d98
|
data/.rubocop.yml
CHANGED
data/Appraisals
ADDED
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
GIT
|
2
2
|
remote: https://github.com/corp-gp/rubocop-gp.git
|
3
|
-
revision:
|
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
|
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.
|
24
|
-
actionview (= 7.
|
25
|
-
activesupport (= 7.
|
26
|
-
|
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.
|
29
|
-
rails-html-sanitizer (~> 1.
|
30
|
-
|
31
|
-
|
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.
|
34
|
-
rails-dom-testing (~> 2.
|
35
|
-
rails-html-sanitizer (~> 1.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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.
|
64
|
+
concurrent-ruby (1.3.5)
|
65
|
+
connection_pool (2.5.0)
|
53
66
|
crass (1.0.6)
|
54
|
-
|
55
|
-
|
56
|
-
dotenv
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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.
|
68
|
-
|
69
|
-
|
70
|
-
|
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.
|
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
|
108
|
+
parser (3.3.7.4)
|
76
109
|
ast (~> 2.4.1)
|
77
110
|
racc
|
78
|
-
pg (1.
|
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 (
|
81
|
-
rack-
|
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
|
-
|
84
|
-
|
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.
|
87
|
-
loofah (~> 2.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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.
|
141
|
+
thor (~> 1.0, >= 1.2.2)
|
142
|
+
zeitwerk (~> 2.6)
|
95
143
|
rainbow (3.1.1)
|
96
|
-
rake (13.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
rspec-
|
104
|
-
|
105
|
-
rspec-
|
106
|
-
rspec-
|
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.
|
109
|
-
rspec-mocks (3.
|
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.
|
112
|
-
rspec-rails (
|
113
|
-
actionpack (>=
|
114
|
-
activesupport (>=
|
115
|
-
railties (>=
|
116
|
-
rspec-core (~> 3.
|
117
|
-
rspec-expectations (~> 3.
|
118
|
-
rspec-mocks (~> 3.
|
119
|
-
rspec-support (~> 3.
|
120
|
-
rspec-support (3.
|
121
|
-
rubocop (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 (
|
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.
|
128
|
-
|
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, <
|
132
|
-
rubocop-ast (1.
|
133
|
-
parser (>= 3.3.
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
rubocop (~> 1.
|
138
|
-
rubocop-
|
139
|
-
|
140
|
-
rubocop
|
141
|
-
rubocop-
|
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.
|
145
|
-
rubocop-ast (>= 1.
|
146
|
-
rubocop-rspec (3.0
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
153
|
-
|
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 (
|
157
|
-
|
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
|
-
|
161
|
-
|
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.
|
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:
|
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
|
-
|
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(
|
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(
|
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)
|
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
|
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
|
-
|
71
|
-
AND #{table_name}
|
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}
|
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
|
-
|
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
|
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.
|
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:
|
11
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: appraisal
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
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: '
|
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.
|
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
|