tapsoob 0.3.21-java → 0.3.26-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: 58cd9a0f8c1ad8356c661c091d51d53e515aee22b746622f08173e31eaef7edf
4
- data.tar.gz: 6802b841f8c59cb73687c1f22a0e696ae26f23732871f44063bbf712290a1ea2
3
+ metadata.gz: 9257ce158006409f702d21898b3352d8269aa1dd4459096e76b89521125e45be
4
+ data.tar.gz: 45c341a28a30a5ac78d68b426b9afae60bb604172c9dd2bd7b2b0333774d4a97
5
5
  SHA512:
6
- metadata.gz: f2d55a4ce17d26490e587e118bdcbe43f9430b7c9cbd0c9672c17dd358d37d9c203564a8c04cd6638a326f50966e6dc5a657a7dbecd1c40a08ca94ced1c21876
7
- data.tar.gz: 2ec0bb229614e453d5832f60b14cfd7e98e5a3cbec264499d0b50cfb77bd1790ba4505a599c3fd21af87ae1bb4da4c5f215e3ff34cb23c9b583cc5473aba1402
6
+ metadata.gz: 0d7a546a51d161e10bc35e7059cc80b1df2061653763daac67f8a3189ebb7b4d63fb68eff14150f13cedbcfb150142f1d3cc8401aaa1d97cf70aed9d7167fdbf
7
+ data.tar.gz: 12ab879416b51181480181e6ca41e538e332b2c88c94d40e968d68eff69069b1d98b7442b284aa429d016c07e9dcb1a6a0c2253d93982c5afda9d7f0e56a42a4
@@ -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 :"discard-identity", desc: "Remove identity when pushing data (may result in creating duplicates)", default: false, type: :boolean
42
43
  option :debug, desc: "Enable debug messages", default: false, type: :boolean, aliases: "-d"
43
44
  def push(dump_path, database_url)
44
45
  opts = parse_opts(options)
@@ -71,8 +72,9 @@ module Tapsoob
71
72
  debug: options[:debug]
72
73
  }
73
74
 
74
- # Purge (push only)
75
+ # Push only options
75
76
  opts[:purge] = options[:purge] if options.key?(:purge)
77
+ opts[:"discard-identity"] = options[:"discard-identity"] if options.key?(:"discard-identity")
76
78
 
77
79
  # Resume
78
80
  if options[:resume]
@@ -1,4 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
+ require 'date'
3
+ require 'time'
4
+
2
5
  require 'tapsoob/log'
3
6
  require 'tapsoob/utils'
4
7
 
@@ -6,9 +9,9 @@ module Tapsoob
6
9
  class DataStream
7
10
  DEFAULT_CHUNKSIZE = 1000
8
11
 
9
- attr_reader :db, :state
12
+ attr_reader :db, :state, :options
10
13
 
11
- def initialize(db, state)
14
+ def initialize(db, state, opts = {})
12
15
  @db = db
13
16
  @state = {
14
17
  :offset => 0,
@@ -17,6 +20,7 @@ module Tapsoob
17
20
  :total_chunksize => 0
18
21
  }.merge(state)
19
22
  @state[:chunksize] ||= DEFAULT_CHUNKSIZE
23
+ @options = opts
20
24
  @complete = false
21
25
  end
22
26
 
@@ -218,6 +222,9 @@ module Tapsoob
218
222
  end
219
223
 
220
224
  def import_rows(rows)
225
+ columns = rows[:header]
226
+ data = rows[:data]
227
+
221
228
  # Decode blobs
222
229
  if rows.has_key?(:types) && rows[:types].include?("blob")
223
230
  blob_indices = rows[:types].each_index.select { |idx| rows[:types][idx] == "blob" }
@@ -227,8 +234,38 @@ module Tapsoob
227
234
  end
228
235
  end
229
236
  end
237
+
238
+ # Parse date/datetime/time columns
239
+ if rows.has_key?(:types)
240
+ %w(date datetime time).each do |type|
241
+ if rows[:types].include?(type)
242
+ klass = case type
243
+ when "date"
244
+ Date
245
+ when "datetime"
246
+ DateTime
247
+ when "time"
248
+ Time
249
+ end
250
+
251
+
252
+ type_indices = rows[:types].each_index.select { |idx| rows[:types][idx] == type }
253
+ rows[:data].each_index do |idx|
254
+ type_indices.each do |ti|
255
+ rows[:data][idx][ti] = klass.parse(rows[:data][idx][ti])
256
+ end
257
+ end
258
+ end
259
+ end
260
+ end
261
+
262
+ # Remove id column
263
+ if @options[:"discard-identity"]
264
+ columns = rows[:header] - ["id"]
265
+ data = data.map { |d| d[1..-1] }
266
+ end
230
267
 
231
- table.import(rows[:header], rows[:data], :commit_every => 100)
268
+ table.import(columns, data, :commit_every => 100)
232
269
  state[:offset] += rows[:data].size
233
270
  rescue Exception => ex
234
271
  case ex.message
@@ -246,19 +283,19 @@ module Tapsoob
246
283
  state[:offset] = table.count
247
284
  end
248
285
 
249
- def self.factory(db, state)
286
+ def self.factory(db, state, opts)
250
287
  if defined?(Sequel::MySQL) && Sequel::MySQL.respond_to?(:convert_invalid_date_time=)
251
288
  Sequel::MySQL.convert_invalid_date_time = :nil
252
289
  end
253
290
 
254
291
  if state.has_key?(:klass)
255
- return eval(state[:klass]).new(db, state)
292
+ return eval(state[:klass]).new(db, state, opts)
256
293
  end
257
294
 
258
295
  if Tapsoob::Utils.single_integer_primary_key(db, state[:table_name].to_sym)
259
- DataStreamKeyed.new(db, state)
296
+ DataStreamKeyed.new(db, state, opts)
260
297
  else
261
- DataStream.new(db, state)
298
+ DataStream.new(db, state, opts)
262
299
  end
263
300
  end
264
301
  end
@@ -266,8 +303,8 @@ module Tapsoob
266
303
  class DataStreamKeyed < DataStream
267
304
  attr_accessor :buffer
268
305
 
269
- def initialize(db, state)
270
- super(db, state)
306
+ def initialize(db, state, opts = {})
307
+ super(db, state, opts)
271
308
  @state = { :primary_key => order_by(state[:table_name]).first, :filter => 0 }.merge(@state)
272
309
  @state[:chunksize] ||= DEFAULT_CHUNKSIZE
273
310
  @buffer = []
@@ -394,9 +394,9 @@ module Tapsoob
394
394
  tables.each do |table_name, count|
395
395
  next unless File.exists?(File.join(dump_path, "data", "#{table_name}.json"))
396
396
  db[table_name.to_sym].truncate if @opts[:purge]
397
- stream = Tapsoob::DataStream.factory(db,
397
+ stream = Tapsoob::DataStream.factory(db, {
398
398
  :table_name => table_name,
399
- :chunksize => default_chunksize)
399
+ :chunksize => default_chunksize }, { :"discard-identity" => @opts[:"discard-identity"] || false })
400
400
  progress = ProgressBar.new(table_name.to_s, count)
401
401
  push_data_from_file(stream, progress)
402
402
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Tapsoob
3
- VERSION = "0.3.21".freeze
3
+ VERSION = "0.3.26".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.21
4
+ version: 0.3.26
5
5
  platform: java
6
6
  authors:
7
7
  - Félix Bellanger