tapsoob 0.4.1-java → 0.4.6-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c06335f502637ae12395ff3c5d183297a64c650cfebe4df4f7383e45e87ebaa
4
- data.tar.gz: f12f5540fdbc10d947ca5d224b816f055a5f4f543c26be47b15c9fed8476ec96
3
+ metadata.gz: 23758087d2ab0e0bcbb62fab53c82050b95a672beef2e494d4270d9cc23ddc4c
4
+ data.tar.gz: 852eaf58cafbb99de7c39ed905486f04a329c99812cd8901104d115b7f865db4
5
5
  SHA512:
6
- metadata.gz: c04ab5686c8bd94b517b023b71bcb5910072b4e271ac822d2d4866bb03a376a5d358dfce9b32cb1eb37f047de9eb676d404488c9313240a55714cf038a13c713
7
- data.tar.gz: e65ac3b651435e35c4abbfcb0318e30d32310f3e58274d0b36ffe0ea14eaf3aa52995cef440589c4d4cd4016201c665baee161c3e4020c53ae37f791f9017383
6
+ metadata.gz: b85de76b17288c4cb2dae29fca2d4acef194943c951e27d4e270b834f10d93abb5ee1650861a505e5db2bab209182a9e6aaff147699ad2dc3a441d0ba8c050ab
7
+ data.tar.gz: 6e7922952e53f067790dcb1dd9b44c8b5c16b08af338e363da02388ae70856e5dae86a8398680041a3f3c3aff1c1cdb44b3b1dbc8bb828cc2459920e1dd8184a
@@ -29,6 +29,7 @@ module Tapsoob
29
29
  option :"exclude-tables", desc: "Shortcut to exclude a list of tables", type: :array, aliases: "-e"
30
30
  option :progress, desc: "Show progress", default: true, type: :boolean, aliases: "-p"
31
31
  option :purge, desc: "Purge data in tables prior to performing the import", default: false, type: :boolean, aliases: "-p"
32
+ option :"skip-duplicates", desc: "Remove duplicates when loading data", default: false, type: :boolean
32
33
  option :"discard-identity", desc: "Remove identity when pushing data (may result in creating duplicates)", default: false, type: :boolean
33
34
  option :debug, desc: "Enable debug messages", default: false, type: :boolean, aliases: "-d"
34
35
  def push(database_url, dump_path = nil)
@@ -69,6 +70,7 @@ module Tapsoob
69
70
 
70
71
  # Push only options
71
72
  opts[:purge] = options[:purge] if options.key?(:purge)
73
+ opts[:"skip-duplicates"] = options[:"skip-duplicates"] if options.key?(:"skip-duplicates")
72
74
  opts[:"discard-identity"] = options[:"discard-identity"] if options.key?(:"discard-identity")
73
75
 
74
76
  # Default chunksize
@@ -39,6 +39,7 @@ module Tapsoob
39
39
  option :tables, desc: "Shortcut to filter on a list of tables", type: :array, aliases: "-t"
40
40
  option :"exclude-tables", desc: "Shortcut to exclude a list of tables", type: :array, aliases: "-e"
41
41
  option :purge, desc: "Purge data in tables prior to performing the import", default: false, type: :boolean, aliases: "-p"
42
+ option :"skip-duplicates", desc: "Remove duplicates when loading data", default: false, type: :boolean
42
43
  option :"discard-identity", desc: "Remove identity when pushing data (may result in creating duplicates)", default: false, type: :boolean
43
44
  option :debug, desc: "Enable debug messages", default: false, type: :boolean, aliases: "-d"
44
45
  def push(dump_path, database_url)
@@ -74,6 +75,7 @@ module Tapsoob
74
75
 
75
76
  # Push only options
76
77
  opts[:purge] = options[:purge] if options.key?(:purge)
78
+ opts[:"skip-duplicates"] = options[:"skip-duplicates"] if options.key?(:"skip-duplicates")
77
79
  opts[:"discard-identity"] = options[:"discard-identity"] if options.key?(:"discard-identity")
78
80
 
79
81
  # Resume
@@ -91,7 +91,7 @@ module Tapsoob
91
91
  rows = {
92
92
  :table_name => ds["table_name"],
93
93
  :header => ds["header"],
94
- :data => (ds["data"][state[:offset], (state[:offset] + state[:chunksize])] || [ ]),
94
+ :data => ((@options[:"skip-duplicates"] ? ds["data"].uniq : ds["data"])[state[:offset], (state[:offset] + state[:chunksize])] || [ ]),
95
95
  :types => ds["types"]
96
96
  }
97
97
  update_chunksize_stats
@@ -152,7 +152,7 @@ module Tapsoob
152
152
 
153
153
  rows = parse_encoded_data(encoded_data, json[:checksum])
154
154
 
155
- @complete = rows == { }
155
+ @complete = rows[:data] == [ ]
156
156
 
157
157
  # update local state
158
158
  state.merge!(json[:state].merge(:chunksize => state[:chunksize]))
@@ -227,8 +227,6 @@ module Tapsoob
227
227
  Tapsoob::Utils.export_rows(dump_path, stream.table_name, rows)
228
228
  end
229
229
  end
230
- break if stream.complete?
231
- progress.inc(size) if progress && !exiting?
232
230
  stream.error = false
233
231
  self.stream_state = stream.to_hash
234
232
  rescue Tapsoob::CorruptedData => e
@@ -236,6 +234,9 @@ module Tapsoob
236
234
  stream.error = true
237
235
  next
238
236
  end
237
+
238
+ progress.inc(size) if progress && !exiting?
239
+ break if stream.complete?
239
240
  end
240
241
 
241
242
  progress.finish if progress
@@ -393,10 +394,16 @@ module Tapsoob
393
394
 
394
395
  tables.each do |table_name, count|
395
396
  next unless File.exists?(File.join(dump_path, "data", "#{table_name}.json"))
396
- db[table.to_sym].truncate if @opts[:purge]
397
+ db[table_name.to_sym].truncate if @opts[:purge]
397
398
  stream = Tapsoob::DataStream.factory(db, {
398
399
  :table_name => table_name,
399
- :chunksize => default_chunksize }, { :"discard-identity" => opts[:"discard-identity"] || false, :purge => opts[:purge] || false, :debug => opts[:debug] })
400
+ :chunksize => default_chunksize
401
+ }, {
402
+ :"skip-duplicates" => opts[:"skip-duplicates"] || false,
403
+ :"discard-identity" => opts[:"discard-identity"] || false,
404
+ :purge => opts[:purge] || false,
405
+ :debug => opts[:debug]
406
+ })
400
407
  progress = ProgressBar.new(table_name.to_s, count)
401
408
  push_data_from_file(stream, progress)
402
409
  end
@@ -22,7 +22,7 @@ class ProgressBar
22
22
  @current = 0
23
23
  @previous = 0
24
24
  @finished_p = false
25
- @start_time = Time.now
25
+ @start_time = ::Time.now
26
26
  @previous_time = @start_time
27
27
  @title_width = 14
28
28
  @format = "%-#{@title_width}s %3d%% %s %s"
@@ -76,7 +76,7 @@ class ProgressBar
76
76
  end
77
77
 
78
78
  def transfer_rate
79
- bytes_per_second = @current.to_f / (Time.now - @start_time)
79
+ bytes_per_second = @current.to_f / (::Time.now - @start_time)
80
80
  sprintf("%s/s", convert_bytes(bytes_per_second))
81
81
  end
82
82
 
@@ -97,14 +97,14 @@ class ProgressBar
97
97
  if @current == 0
98
98
  "ETA: --:--:--"
99
99
  else
100
- elapsed = Time.now - @start_time
100
+ elapsed = ::Time.now - @start_time
101
101
  eta = elapsed * @total / @current - elapsed;
102
102
  sprintf("ETA: %s", format_time(eta))
103
103
  end
104
104
  end
105
105
 
106
106
  def elapsed
107
- elapsed = Time.now - @start_time
107
+ elapsed = ::Time.now - @start_time
108
108
  sprintf("Time: %s", format_time(elapsed))
109
109
  end
110
110
 
@@ -155,7 +155,7 @@ class ProgressBar
155
155
  @terminal_width += width - line.length + 1
156
156
  show
157
157
  end
158
- @previous_time = Time.now
158
+ @previous_time = ::Time.now
159
159
  end
160
160
 
161
161
  def show_if_needed
@@ -169,7 +169,7 @@ class ProgressBar
169
169
 
170
170
  # Use "!=" instead of ">" to support negative changes
171
171
  if cur_percentage != prev_percentage ||
172
- Time.now - @previous_time >= 1 || @finished_p
172
+ ::Time.now - @previous_time >= 1 || @finished_p
173
173
  show
174
174
  end
175
175
  end
data/lib/tapsoob/utils.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require 'zlib'
3
+ require 'active_support/core_ext/file/atomic.rb'
3
4
 
4
5
  require 'tapsoob/errors'
5
6
  require 'tapsoob/chunksize'
@@ -143,10 +144,10 @@ Data : #{data}
143
144
  data = row_data
144
145
  if File.exists?(File.join(dump_path, "data", "#{table}.json"))
145
146
  previous_data = JSON.parse(File.read(File.join(dump_path, "data", "#{table}.json")))
146
- data[:data] = previous_data["data"] + row_data[:data]
147
+ data[:data] = (previous_data["data"].nil? ? row_data[:data] : previous_data["data"] + row_data[:data])
147
148
  end
148
149
 
149
- File.open(File.join(dump_path, "data", "#{table}.json"), 'w') do |file|
150
+ File.atomic_write(File.join(dump_path, "data", "#{table}.json")) do |file|
150
151
  file.write(JSON.generate(data))
151
152
  end
152
153
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Tapsoob
3
- VERSION = "0.4.1".freeze
3
+ VERSION = "0.4.6".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapsoob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.6
5
5
  platform: java
6
6
  authors:
7
7
  - Félix Bellanger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-06-21 00:00:00.000000000 Z
12
+ date: 2021-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement