pgslice 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/pgslice/version.rb +1 -1
- data/lib/pgslice.rb +16 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e0437c8314b62daec17ddf072a9f269fa6b7aa1
|
4
|
+
data.tar.gz: 311105b8057bc43cf9ff75a7a8be0dc62b707c9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4db509fb649e78d0fac104071e58621b54a01bc5b17b53bbd5aa786ee9908e657ed6adaf6e407ffae28cfc81549cdde76512e4a6b9195a18ac421ac31eb21755
|
7
|
+
data.tar.gz: a43f16632bca4827762396778d3ed23718046f774e584ef65b6a48af8245d195014c4f628a190f9e58c0d534b4bd9b8aaf4dd59d776d4428e9f56afdaacc69ae
|
data/CHANGELOG.md
CHANGED
data/lib/pgslice/version.rb
CHANGED
data/lib/pgslice.rb
CHANGED
@@ -214,13 +214,14 @@ CREATE OR REPLACE FUNCTION #{trigger_name}()
|
|
214
214
|
abort "Usage: pgslice fill <table>" if arguments.length != 1
|
215
215
|
|
216
216
|
source_table = options[:source_table]
|
217
|
+
dest_table = options[:dest_table]
|
217
218
|
|
218
219
|
if options[:swapped]
|
219
220
|
source_table ||= retired_name(table)
|
220
|
-
dest_table
|
221
|
+
dest_table ||= table
|
221
222
|
else
|
222
223
|
source_table ||= table
|
223
|
-
dest_table
|
224
|
+
dest_table ||= intermediate_name(table)
|
224
225
|
end
|
225
226
|
|
226
227
|
abort "Table not found: #{source_table}" unless table_exists?(source_table)
|
@@ -232,17 +233,19 @@ CREATE OR REPLACE FUNCTION #{trigger_name}()
|
|
232
233
|
name_format = self.name_format(period)
|
233
234
|
|
234
235
|
existing_tables = self.existing_tables(like: "#{table}_%").select { |t| /#{Regexp.escape("#{table}_")}(\d{4,6})/.match(t) }.sort
|
235
|
-
|
236
|
-
|
236
|
+
if existing_tables.any?
|
237
|
+
starting_time = DateTime.strptime(existing_tables.first.split("_").last, name_format)
|
238
|
+
ending_time = advance_date(DateTime.strptime(existing_tables.last.split("_").last, name_format), period, 1)
|
239
|
+
end
|
237
240
|
end
|
238
241
|
|
239
242
|
primary_key = self.primary_key(table)
|
240
243
|
max_source_id = max_id(source_table, primary_key)
|
241
244
|
max_dest_id =
|
242
245
|
if options[:swapped]
|
243
|
-
max_id(dest_table, primary_key, below: max_source_id)
|
246
|
+
max_id(dest_table, primary_key, where: options[:where], below: max_source_id)
|
244
247
|
else
|
245
|
-
max_id(dest_table, primary_key)
|
248
|
+
max_id(dest_table, primary_key, where: options[:where])
|
246
249
|
end
|
247
250
|
|
248
251
|
if max_dest_id == 0 && !options[:swapped]
|
@@ -262,7 +265,7 @@ CREATE OR REPLACE FUNCTION #{trigger_name}()
|
|
262
265
|
batch_count = ((max_source_id - starting_id) / batch_size.to_f).ceil
|
263
266
|
while starting_id < max_source_id
|
264
267
|
where = "#{primary_key} > #{starting_id} AND #{primary_key} <= #{starting_id + batch_size}"
|
265
|
-
if
|
268
|
+
if starting_time
|
266
269
|
where << " AND #{field} >= #{sql_date(starting_time)} AND #{field} < #{sql_date(ending_time)}"
|
267
270
|
end
|
268
271
|
if options[:where]
|
@@ -350,6 +353,7 @@ INSERT INTO #{dest_table} (#{fields})
|
|
350
353
|
o.integer "--start"
|
351
354
|
o.string "--url"
|
352
355
|
o.string "--source-table"
|
356
|
+
o.string "--dest-table"
|
353
357
|
o.string "--where"
|
354
358
|
o.string "--lock-timeout", default: "5s"
|
355
359
|
o.on "-v", "--version", "print the version" do
|
@@ -460,9 +464,12 @@ INSERT INTO #{dest_table} (#{fields})
|
|
460
464
|
row && row["attname"]
|
461
465
|
end
|
462
466
|
|
463
|
-
def max_id(table, primary_key, below: nil)
|
467
|
+
def max_id(table, primary_key, below: nil, where: nil)
|
464
468
|
query = "SELECT MAX(#{primary_key}) FROM #{table}"
|
465
|
-
|
469
|
+
conditions = []
|
470
|
+
conditions << "#{primary_key} <= #{below}" if below
|
471
|
+
conditions << where if where
|
472
|
+
query << " WHERE #{conditions.join(" AND ")}" if conditions.any?
|
466
473
|
execute(query)[0]["max"].to_i
|
467
474
|
end
|
468
475
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgslice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|