tapsoob 0.3.27 → 0.4.0

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: b7b43f7fe0ec4c4f90c32f00e0ca57ab252c78cdf5f13dfe1c689f8d7a031d32
4
- data.tar.gz: 3d27c0eb39663d9766d1104df903045be1ddbd1580cfcf854e0ea6a98eb64f70
3
+ metadata.gz: 469c560664c5ba21ac179589064ae693ec3cc158d5a2d9ad2a9a0117a3657c71
4
+ data.tar.gz: b05907cdcf4df4ffeb66fcf3cd086f8083b84b1189f559aca4cb1ef1661fd7ca
5
5
  SHA512:
6
- metadata.gz: be0a84840b6036dfd5ee03a4c659978eb38b30353961f2797bdb03a6f5ea6fddad407ff3442252a87f0619968cafe57a7c52f7c3102de8757b70ffaf2babd0d4
7
- data.tar.gz: c415ccc0c1d035ece72938c443ff2deba691432f4f9baa6560cba29eac0537bd7c48579a5640727af5f2a42091b2ffdffb63fd2c88bb90f7cf4c266a86449990
6
+ metadata.gz: cfe9c901740ae209bf8abf7cc534edfeba3e6a209da81acc2ae6776fa4a79ec28b7d1425c9ae4825aff07ae4e4fe9a5b0a1df1769c57ea22a513bb0013a54d9d
7
+ data.tar.gz: 5768ef7b85b8188215a82d9f00177d51443558e62baf4085ea4ec007116a844587e145cd1d4a6b507aea93e1066a8c5f60caa95630665dacf0fb77ca70908107
@@ -28,6 +28,8 @@ module Tapsoob
28
28
  option :tables, desc: "Shortcut to filter on a list of tables", type: :array, aliases: "-t"
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
+ option :purge, desc: "Purge data in tables prior to performing the import", default: false, type: :boolean, aliases: "-p"
32
+ option :"discard-identity", desc: "Remove identity when pushing data (may result in creating duplicates)", default: false, type: :boolean
31
33
  option :debug, desc: "Enable debug messages", default: false, type: :boolean, aliases: "-d"
32
34
  def push(database_url, dump_path = nil)
33
35
  # instantiate stuff
@@ -46,9 +48,8 @@ module Tapsoob
46
48
  data.each do |table|
47
49
  stream = Tapsoob::DataStream.factory(db(database_url, opts), {
48
50
  table_name: table[:table_name],
49
- chunksize: opts[:default_chunksize],
50
- debug: opts[:debug]
51
- })
51
+ chunksize: opts[:default_chunksize]
52
+ }, { :"discard-identity" => opts[:"discard-identity"] || false, :purge => opts[:purge] || false, :debug => opts[:debug] })
52
53
 
53
54
  begin
54
55
  stream.import_rows(table)
@@ -66,6 +67,10 @@ module Tapsoob
66
67
  debug: options[:debug]
67
68
  }
68
69
 
70
+ # Push only options
71
+ opts[:purge] = options[:purge] if options.key?(:purge)
72
+ opts[:"discard-identity"] = options[:"discard-identity"] if options.key?(:"discard-identity")
73
+
69
74
  # Default chunksize
70
75
  if options[:chunksize]
71
76
  opts[:default_chunksize] = (options[:chunksize] < 10 ? 10 : options[:chunksize])
@@ -91,7 +91,8 @@ 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 => (ds["data"][state[:offset], (state[:offset] + state[:chunksize])] || [ ]),
95
+ :types => ds["types"]
95
96
  }
96
97
  update_chunksize_stats
97
98
  rows
@@ -222,12 +223,24 @@ module Tapsoob
222
223
  columns = rows[:header]
223
224
  data = rows[:data]
224
225
 
226
+ # Only import existing columns
227
+ if table.columns.size != columns.size
228
+ existing_columns = table.columns.map(&:to_s)
229
+ additional_columns = columns - existing_columns
230
+ additional_columns_idxs = additional_columns.map { |c| columns.index(c) }
231
+ additional_columns_idxs.reverse.each do |idx|
232
+ columns.delete_at(idx)
233
+ rows[:types].delete_at(idx)
234
+ end
235
+ data.each_index { |didx| additional_columns_idxs.reverse.each { |idx| data[didx].delete_at(idx) } }
236
+ end
237
+
225
238
  # Decode blobs
226
239
  if rows.has_key?(:types) && rows[:types].include?("blob")
227
240
  blob_indices = rows[:types].each_index.select { |idx| rows[:types][idx] == "blob" }
228
- rows[:data].each_index do |idx|
241
+ data.each_index do |idx|
229
242
  blob_indices.each do |bi|
230
- rows[:data][idx][bi] = Sequel::SQL::Blob.new(Tapsoob::Utils.base64decode(rows[:data][idx][bi])) unless rows[:data][idx][bi].nil?
243
+ data[idx][bi] = Sequel::SQL::Blob.new(Tapsoob::Utils.base64decode(data[idx][bi])) unless data[idx][bi].nil?
231
244
  end
232
245
  end
233
246
  end
@@ -237,9 +250,9 @@ module Tapsoob
237
250
  %w(date datetime time).each do |type|
238
251
  if rows[:types].include?(type)
239
252
  type_indices = rows[:types].each_index.select { |idx| rows[:types][idx] == type }
240
- rows[:data].each_index do |idx|
253
+ data.each_index do |idx|
241
254
  type_indices.each do |ti|
242
- rows[:data][idx][ti] = Sequel.send("string_to_#{type}".to_sym, rows[:data][idx][ti])
255
+ data[idx][ti] = Sequel.send("string_to_#{type}".to_sym, data[idx][ti]) unless data[idx][ti].nil?
243
256
  end
244
257
  end
245
258
  end
@@ -247,11 +260,11 @@ module Tapsoob
247
260
  end
248
261
 
249
262
  # Remove id column
250
- if @options[:"discard-identity"]
263
+ if @options[:"discard-identity"] && rows[:header].include?("id")
251
264
  columns = rows[:header] - ["id"]
252
265
  data = data.map { |d| d[1..-1] }
253
266
  end
254
-
267
+
255
268
  table.import(columns, data, :commit_every => 100)
256
269
  state[:offset] += rows[:data].size
257
270
  rescue Exception => ex
@@ -198,7 +198,7 @@ module Tapsoob
198
198
  stream = Tapsoob::DataStream.factory(db, {
199
199
  :chunksize => default_chunksize,
200
200
  :table_name => table_name
201
- })
201
+ }, { :debug => opts[:debug] }))
202
202
  pull_data_from_table(stream, progress)
203
203
  end
204
204
  end
@@ -393,10 +393,10 @@ module Tapsoob
393
393
 
394
394
  tables.each do |table_name, count|
395
395
  next unless File.exists?(File.join(dump_path, "data", "#{table_name}.json"))
396
- db[table_name.to_sym].truncate if @opts[:purge]
396
+ db[table.to_sym].truncate if @opts[:purge]
397
397
  stream = Tapsoob::DataStream.factory(db, {
398
398
  :table_name => table_name,
399
- :chunksize => default_chunksize }, { :"discard-identity" => @opts[:"discard-identity"] || false })
399
+ :chunksize => default_chunksize }, { :"discard-identity" => opts[:"discard-identity"] || false, :purge => opts[:purge] || false, :debug => opts[:debug] })
400
400
  progress = ProgressBar.new(table_name.to_s, count)
401
401
  push_data_from_file(stream, progress)
402
402
  end
@@ -429,7 +429,8 @@ module Tapsoob
429
429
  }
430
430
  end
431
431
 
432
- size = stream.fetch_data_in_database({ :encoded_data => encoded_data, :checksum => data[:checksum] })
432
+ row_size = stream.fetch_data_in_database({ :encoded_data => encoded_data, :checksum => data[:checksum] })
433
+ log.debug "row size: #{row_size}"
433
434
  self.stream_state = stream.to_hash
434
435
 
435
436
  c.idle_secs = (d1 + d2)
@@ -481,7 +482,7 @@ module Tapsoob
481
482
  tbls.each do |table|
482
483
  if File.exists?(File.join(dump_path, "data", "#{table}.json"))
483
484
  data = JSON.parse(File.read(File.join(dump_path, "data", "#{table}.json")))
484
- tables_with_counts[table] = data.size
485
+ tables_with_counts[table] = data["data"].size
485
486
  else
486
487
  tables_with_counts[table] = 0
487
488
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Tapsoob
3
- VERSION = "0.3.27".freeze
3
+ VERSION = "0.4.0".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.3.27
4
+ version: 0.4.0
5
5
  platform: ruby
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-11 00:00:00.000000000 Z
12
+ date: 2021-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ripl