tapsoob 0.3.21 → 0.3.22

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: 7109b252c22de2c4c796068f6ac2fc4df267e4b1130ee875a40b08f9ee7a1224
4
- data.tar.gz: 5530cb2317ae8a4829335b20e90bbb1788a546f898839a1f330c379ecd2973c1
3
+ metadata.gz: 39668125ecb9a04823357801014aafd32b66b497ebe0e067b9b4cb19e641f04e
4
+ data.tar.gz: fe1b3dd5eb413addbc09960ec659cc935c40ce8ce416900dd0f5784369cb2e43
5
5
  SHA512:
6
- metadata.gz: cf1960e1ef01a40a0e22f66a042616d7a16b3030f8c7ad20227b7ab44805b175872ec3b030d4e1a3c08469ccf3a33f606b8bcdd14bfddb58ce2378ade773dfac
7
- data.tar.gz: 9abb44b2ca81049159c78dc771938bb13e8334f008f51d9c899f5b8c22928621d003a429537fc639eef713d3005ce9804731b09db95d5bde24f97d2615dd7bef
6
+ metadata.gz: eda88cd4c768141b177fd44cbb05392941d23a7bf285bcda2890d8b35bd972121b6fe6a8407b155ef8074abc971c991a1f8f41af9ed447643f4f8d88332adb6d
7
+ data.tar.gz: 7d2339542cb0b2c246cebdb2908f371cb695ce273eac7c11cabe1122a86febdbc947d293ca5c92601c1243d9c130a0026bb4d85f9d4e6036b8c2fddf78ba0a6e
@@ -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]
@@ -6,9 +6,9 @@ module Tapsoob
6
6
  class DataStream
7
7
  DEFAULT_CHUNKSIZE = 1000
8
8
 
9
- attr_reader :db, :state
9
+ attr_reader :db, :state, :options
10
10
 
11
- def initialize(db, state)
11
+ def initialize(db, state, opts = {})
12
12
  @db = db
13
13
  @state = {
14
14
  :offset => 0,
@@ -17,6 +17,7 @@ module Tapsoob
17
17
  :total_chunksize => 0
18
18
  }.merge(state)
19
19
  @state[:chunksize] ||= DEFAULT_CHUNKSIZE
20
+ @options = opts
20
21
  @complete = false
21
22
  end
22
23
 
@@ -227,8 +228,11 @@ module Tapsoob
227
228
  end
228
229
  end
229
230
  end
231
+
232
+ # Remove id column
233
+ columns = ((@options[:"discard-identity"] && rows[:headers].include?("id")) ? rows[:headers] - ["id"] : rows[:headers])
230
234
 
231
- table.import(rows[:header], rows[:data], :commit_every => 100)
235
+ table.import(columns, rows[:data], :commit_every => 100)
232
236
  state[:offset] += rows[:data].size
233
237
  rescue Exception => ex
234
238
  case ex.message
@@ -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.22".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.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Félix Bellanger