pgslice 0.2.1 → 0.2.2
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/README.md +2 -0
- data/lib/pgslice.rb +21 -5
- data/lib/pgslice/version.rb +1 -1
- 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: c5697462268c630c5fd8e72567fe4ac9b903d157
|
4
|
+
data.tar.gz: 686af5d5c45edff42d491f7378f1338299aa6a14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e09e05ebe4cad9c34fae30ca04f6c6fe5ff6a1f3bb175ea55af9e29add720e9d6319939dd92be320d3360957c03cc5756862c8ef1918ff2d5277c7c47e315a88
|
7
|
+
data.tar.gz: cac51539b16171d3a54f4a93d3ee4539ae50b34267727fa883614c341693b49894951537fd45e0e4432ba78bbe8e9f21b1d7a932cf0f3f2ab4967b0c2c0ca2c7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/pgslice.rb
CHANGED
@@ -249,7 +249,7 @@ CREATE OR REPLACE FUNCTION #{trigger_name}()
|
|
249
249
|
if options[:start]
|
250
250
|
max_dest_id = options[:start]
|
251
251
|
else
|
252
|
-
min_source_id = min_id(source_table, primary_key, field, starting_time)
|
252
|
+
min_source_id = min_id(source_table, primary_key, field, starting_time, options[:where])
|
253
253
|
max_dest_id = min_source_id - 1 if min_source_id
|
254
254
|
end
|
255
255
|
end
|
@@ -308,6 +308,8 @@ INSERT INTO #{dest_table} (#{fields})
|
|
308
308
|
queries << "ALTER SEQUENCE #{sequence["sequence_name"]} OWNED BY #{table}.#{sequence["related_column"]};"
|
309
309
|
end
|
310
310
|
|
311
|
+
queries.unshift("SET LOCAL lock_timeout = '#{options[:lock_timeout]}';") if server_version_num >= 90300
|
312
|
+
|
311
313
|
run_queries(queries)
|
312
314
|
end
|
313
315
|
|
@@ -349,6 +351,7 @@ INSERT INTO #{dest_table} (#{fields})
|
|
349
351
|
o.string "--url"
|
350
352
|
o.string "--source-table"
|
351
353
|
o.string "--where"
|
354
|
+
o.string "--lock-timeout", default: "5s"
|
352
355
|
o.on "-v", "--version", "print the version" do
|
353
356
|
log PgSlice::VERSION
|
354
357
|
@exit = true
|
@@ -401,18 +404,28 @@ INSERT INTO #{dest_table} (#{fields})
|
|
401
404
|
|
402
405
|
def run_queries(queries)
|
403
406
|
connection.transaction do
|
404
|
-
execute("SET client_min_messages TO warning") unless options[:dry_run]
|
407
|
+
execute("SET LOCAL client_min_messages TO warning") unless options[:dry_run]
|
405
408
|
log_sql "BEGIN;"
|
406
409
|
log_sql
|
407
410
|
queries.each do |query|
|
408
411
|
log_sql query
|
409
412
|
log_sql
|
410
|
-
|
413
|
+
unless options[:dry_run]
|
414
|
+
begin
|
415
|
+
execute(query)
|
416
|
+
rescue PG::ServerError => e
|
417
|
+
abort("#{e.class.name}: #{e.message}")
|
418
|
+
end
|
419
|
+
end
|
411
420
|
end
|
412
421
|
log_sql "COMMIT;"
|
413
422
|
end
|
414
423
|
end
|
415
424
|
|
425
|
+
def server_version_num
|
426
|
+
execute("SHOW server_version_num")[0]["server_version_num"].to_i
|
427
|
+
end
|
428
|
+
|
416
429
|
def existing_tables(like:)
|
417
430
|
query = "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = $1 AND tablename LIKE $2"
|
418
431
|
execute(query, ["public", like]).map { |r| r["tablename"] }.sort
|
@@ -453,9 +466,12 @@ INSERT INTO #{dest_table} (#{fields})
|
|
453
466
|
execute(query)[0]["max"].to_i
|
454
467
|
end
|
455
468
|
|
456
|
-
def min_id(table, primary_key, column, starting_time)
|
469
|
+
def min_id(table, primary_key, column, starting_time, where)
|
457
470
|
query = "SELECT MIN(#{primary_key}) FROM #{table}"
|
458
|
-
|
471
|
+
conditions = []
|
472
|
+
conditions << "#{column} >= #{sql_date(starting_time)}" if starting_time
|
473
|
+
conditions << where if where
|
474
|
+
query << " WHERE #{conditions.join(" AND ")}" if conditions.any?
|
459
475
|
(execute(query)[0]["min"] || 1).to_i
|
460
476
|
end
|
461
477
|
|
data/lib/pgslice/version.rb
CHANGED
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.2
|
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-
|
11
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|