umbrellio-utils 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +21 -22
- data/Gemfile.lock +12 -5
- data/lib/umbrellio_utils/database.rb +31 -11
- data/lib/umbrellio_utils/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: 4ed0221575b9cfc5c5350ea8eed168a30e9804b943c20fc357c8ee36c963d767
|
4
|
+
data.tar.gz: 18eb1859efe000d5c5d2bb13b57217a84651f0f824542f49c8093439b49d8141
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e4077e807ee85ebc7e4db39f3f3e94ee5b75e94fde085082aadcd3d5422a0827522f00d37022cbb1bf6df71a051d5a1faaad53468870fa189f3f496e17d5531
|
7
|
+
data.tar.gz: cdd6bce77b7ab07d9ebc975c08551c73f0804540ae9fbff1145965118db40ec0a7f0719b25166ea6e4e5bff2bbc2d01a316b20cfd4a9761074fa9e93bd9d7987
|
data/Gemfile
CHANGED
@@ -5,25 +5,24 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in umbrellio_utils.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
8
|
+
gem "activesupport"
|
9
|
+
gem "bundler"
|
10
|
+
gem "ci-helper"
|
11
|
+
gem "http"
|
12
|
+
gem "net-pop", github: "ruby/net-pop" # See https://stackoverflow.com/questions/78617432/strange-bundle-update-issue-disappearing-net-pop-0-1-2-dependency
|
13
|
+
gem "nokogiri"
|
14
|
+
gem "nori"
|
15
|
+
gem "pg"
|
16
|
+
gem "pry"
|
17
|
+
gem "rake"
|
18
|
+
gem "rspec"
|
19
|
+
gem "rspec-json_matcher"
|
20
|
+
gem "rubocop-config-umbrellio"
|
21
|
+
gem "semantic_logger"
|
22
|
+
gem "sequel"
|
23
|
+
gem "sequel-batches"
|
24
|
+
gem "simplecov"
|
25
|
+
gem "simplecov-lcov"
|
26
|
+
gem "table_sync"
|
27
|
+
gem "timecop"
|
28
|
+
gem "yard"
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/ruby/net-pop.git
|
3
|
+
revision: e8d0afe2773b9eb6a23c39e9e437f6fc0fc7c733
|
4
|
+
specs:
|
5
|
+
net-pop (0.1.2)
|
6
|
+
net-protocol
|
7
|
+
|
1
8
|
PATH
|
2
9
|
remote: .
|
3
10
|
specs:
|
4
|
-
umbrellio-utils (1.
|
11
|
+
umbrellio-utils (1.4.0)
|
5
12
|
memery (~> 1)
|
6
13
|
|
7
14
|
GEM
|
@@ -106,7 +113,7 @@ GEM
|
|
106
113
|
docile (1.4.0)
|
107
114
|
domain_name (0.6.20240107)
|
108
115
|
drb (2.2.1)
|
109
|
-
dry-inflector (1.
|
116
|
+
dry-inflector (1.1.0)
|
110
117
|
erubi (1.13.0)
|
111
118
|
ffi (1.17.0)
|
112
119
|
ffi (1.17.0-arm64-darwin)
|
@@ -158,7 +165,6 @@ GEM
|
|
158
165
|
net-imap (0.4.14)
|
159
166
|
date
|
160
167
|
net-protocol
|
161
|
-
net-pop (0.1.2)
|
162
168
|
net-protocol (0.2.2)
|
163
169
|
timeout
|
164
170
|
net-smtp (0.5.0)
|
@@ -193,7 +199,7 @@ GEM
|
|
193
199
|
sneakers (~> 2.0)
|
194
200
|
tainbox
|
195
201
|
racc (1.8.0)
|
196
|
-
rack (3.1.
|
202
|
+
rack (3.1.6)
|
197
203
|
rack-session (2.0.0)
|
198
204
|
rack (>= 3.0.0)
|
199
205
|
rack-test (2.1.0)
|
@@ -304,7 +310,7 @@ GEM
|
|
304
310
|
self_data (1.3.0)
|
305
311
|
semantic_logger (4.15.0)
|
306
312
|
concurrent-ruby (~> 1.0)
|
307
|
-
sequel (5.
|
313
|
+
sequel (5.82.0)
|
308
314
|
bigdecimal
|
309
315
|
sequel-batches (2.0.2)
|
310
316
|
sequel
|
@@ -367,6 +373,7 @@ DEPENDENCIES
|
|
367
373
|
bundler
|
368
374
|
ci-helper
|
369
375
|
http
|
376
|
+
net-pop!
|
370
377
|
nokogiri
|
371
378
|
nori
|
372
379
|
pg
|
@@ -22,8 +22,8 @@ module UmbrellioUtils
|
|
22
22
|
error.result.error_field(PG::Result::PG_DIAG_CONSTRAINT_NAME)
|
23
23
|
end
|
24
24
|
|
25
|
-
def each_record(dataset, **options, &block)
|
26
|
-
primary_key = primary_key_from(dataset,
|
25
|
+
def each_record(dataset, primary_key: nil, **options, &block)
|
26
|
+
primary_key = primary_key_from(dataset, primary_key: primary_key)
|
27
27
|
|
28
28
|
with_temp_table(dataset, **options) do |ids|
|
29
29
|
rows = ids.map { |id| row(id.is_a?(Hash) ? id.values : [id]) }
|
@@ -31,11 +31,28 @@ module UmbrellioUtils
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
# Iterates over a dataset and yields batches of primary keys.
|
35
|
+
# First, a temporary table is created and populated with dataset primary keys.
|
36
|
+
# After that, a batch of rows is deleted from the temp table on each iteration
|
37
|
+
# and gets yielded to the caller.
|
38
|
+
# @option [Integer] page_size max size of each yielded PK batch
|
39
|
+
# @option [Integer] sleep interval to sleep between each iteration
|
40
|
+
# @option [Array] primary_key custom primary key to use for dataset
|
41
|
+
# @option [Symbol, String] temp_table_name custom name for temporary table,
|
42
|
+
# table is reused if already exists
|
43
|
+
def with_temp_table(
|
44
|
+
dataset,
|
45
|
+
page_size: 1_000,
|
46
|
+
sleep: nil,
|
47
|
+
primary_key: nil,
|
48
|
+
temp_table_name: nil
|
49
|
+
)
|
50
|
+
primary_key = primary_key_from(dataset, primary_key: primary_key)
|
36
51
|
sleep_interval = sleep_interval_from(sleep)
|
37
52
|
|
38
|
-
temp_table_name = create_temp_table(
|
53
|
+
temp_table_name = create_temp_table(
|
54
|
+
dataset, primary_key: primary_key, temp_table_name: temp_table_name&.to_sym
|
55
|
+
)
|
39
56
|
|
40
57
|
pk_set = []
|
41
58
|
|
@@ -49,23 +66,26 @@ module UmbrellioUtils
|
|
49
66
|
|
50
67
|
Kernel.sleep(sleep_interval) if sleep_interval.positive?
|
51
68
|
end
|
52
|
-
|
69
|
+
|
53
70
|
DB.drop_table(temp_table_name)
|
54
71
|
end
|
55
72
|
|
56
|
-
def create_temp_table(dataset,
|
73
|
+
def create_temp_table(dataset, primary_key: nil, temp_table_name: nil)
|
57
74
|
time = Time.current
|
58
75
|
model = dataset.model
|
59
|
-
|
60
|
-
|
76
|
+
|
77
|
+
temp_table_name ||= :"temp_#{model.table_name}_#{time.to_i}_#{time.nsec}"
|
78
|
+
return temp_table_name if DB.table_exists?(temp_table_name)
|
79
|
+
|
80
|
+
primary_key = primary_key_from(dataset, primary_key: primary_key)
|
61
81
|
|
62
82
|
DB.create_table(temp_table_name, unlogged: true) do
|
63
83
|
primary_key.each do |field|
|
64
84
|
type = model.db_schema[field][:db_type]
|
65
|
-
column
|
85
|
+
column(field, type)
|
66
86
|
end
|
67
87
|
|
68
|
-
primary_key
|
88
|
+
primary_key(primary_key)
|
69
89
|
end
|
70
90
|
|
71
91
|
insert_ds = dataset.select(*qualified_pk(model.table_name, primary_key))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umbrellio-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Team Umbrellio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: memery
|