tapsoob 0.5.27 → 0.5.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9e2d75dd19008094d30f87a528281d1a6df5c0b2bda8faa79a67dbeb2bb22ce
4
- data.tar.gz: 940c827d7dd14127f99116e66ddaa9ceb0d7fcab0127876748e1b571cde7d140
3
+ metadata.gz: 748c9cf97135cae0c72f0ba298f7c3f197e65764ce4c44c0670d8ef2fe5181ed
4
+ data.tar.gz: 7bebc431915dcf8dd5bff0ee341cf22765646d1854485c23f80b5b9c642fc142
5
5
  SHA512:
6
- metadata.gz: 537960e95fb5ae7b5e3d2e022c56fdf26ac989017274fea1f59fe8510e30248c8c8c3a060e70515d7b9db2882748962ae2423a3d9f6e1e63acf65c69b2741065
7
- data.tar.gz: 027f3de686550ba21a5b44106d005526215e8f06667fcb80f8d6b5783423b453f1d1f4aef9be763bcf2e1ac7d4b25b8898a65d6f93798172203b91367d46e8d3
6
+ metadata.gz: 404478581e61ebdd2875c21d0af865acd5e9dba010292819046cd5e195c9c78cad675bdd50216ea26c5bba8923c0e532a8bd2593b4fe7eb0e71f85db865ef067
7
+ data.tar.gz: 3310489ebd6dcfd7efc76c4fd5d9b2ec6ffa9da12c6cb4161ffd02267f376927b957f5142dcf42ba81fd544c470c36e07f7e0263b66bcae6168b6c9dfe309b61
@@ -202,7 +202,7 @@ module Tapsoob
202
202
  :chunksize => default_chunksize,
203
203
  :table_name => table_name
204
204
  }, { :debug => opts[:debug] })
205
- estimated_chunks = (count.to_f / default_chunksize).ceil
205
+ estimated_chunks = [(count.to_f / default_chunksize).ceil, 1].max
206
206
  progress = (opts[:progress] ? ProgressBar.new(table_name.to_s, estimated_chunks) : nil)
207
207
  pull_data_from_table(stream, progress)
208
208
  end
@@ -217,7 +217,7 @@ module Tapsoob
217
217
 
218
218
  stream = Tapsoob::DataStream.factory(db, stream_state)
219
219
  chunksize = stream_state[:chunksize] || default_chunksize
220
- estimated_chunks = (record_count.to_f / chunksize).ceil
220
+ estimated_chunks = [(record_count.to_f / chunksize).ceil, 1].max
221
221
  progress = (opts[:progress] ? ProgressBar.new(table_name.to_s, estimated_chunks) : nil)
222
222
  pull_data_from_table(stream, progress)
223
223
  end
@@ -423,8 +423,10 @@ module Tapsoob
423
423
  table_name = stream_state[:table_name]
424
424
  record_count = tables[table_name.to_s]
425
425
  log.info "Resuming #{table_name}, #{format_number(record_count)} records"
426
- progress = ProgressBar.new(table_name.to_s, record_count)
427
426
  stream = Tapsoob::DataStream.factory(db, stream_state)
427
+ chunksize = stream_state[:chunksize] || default_chunksize
428
+ estimated_chunks = [(record_count.to_f / chunksize).ceil, 1].max
429
+ progress = (opts[:progress] ? ProgressBar.new(table_name.to_s, estimated_chunks) : nil)
428
430
  push_data_from_file(stream, progress)
429
431
  end
430
432
 
@@ -434,7 +436,9 @@ module Tapsoob
434
436
  log.info "#{tables.size} tables, #{format_number(record_count)} records"
435
437
 
436
438
  tables.each do |table_name, count|
437
- next unless File.exist?(File.join(dump_path, "data", "#{table_name}.json")) || File.exist?(File.join(dump_path, "data", "#{table_name}.json")) && JSON.parse(File.read(File.join(dump_path, "data", "#{table_name}.json")))["data"].size == 0
439
+ # Skip if data file doesn't exist or has no data
440
+ data_file = File.join(dump_path, "data", "#{table_name}.json")
441
+ next unless File.exist?(data_file) && count > 0
438
442
  db[table_name.to_sym].truncate if @opts[:purge]
439
443
  stream = Tapsoob::DataStream.factory(db, {
440
444
  :table_name => table_name,
@@ -445,7 +449,8 @@ module Tapsoob
445
449
  :purge => opts[:purge] || false,
446
450
  :debug => opts[:debug]
447
451
  })
448
- progress = (opts[:progress] ? ProgressBar.new(table_name.to_s, count) : nil)
452
+ estimated_chunks = [(count.to_f / default_chunksize).ceil, 1].max
453
+ progress = (opts[:progress] ? ProgressBar.new(table_name.to_s, estimated_chunks) : nil)
449
454
  push_data_from_file(stream, progress)
450
455
  end
451
456
  end
@@ -496,7 +501,8 @@ module Tapsoob
496
501
  end
497
502
  stream.state[:chunksize] = chunksize
498
503
 
499
- progress.inc(row_size) if progress
504
+ # Update progress bar by 1 chunk
505
+ progress.inc(1) if progress
500
506
 
501
507
  break if stream.complete?
502
508
  end
@@ -528,8 +534,13 @@ module Tapsoob
528
534
  tbls = Dir.glob(File.join(dump_path, "schemas", "*")).map { |path| File.basename(path, ".rb") }
529
535
  tbls.each do |table|
530
536
  if File.exist?(File.join(dump_path, "data", "#{table}.json"))
531
- data = JSON.parse(File.read(File.join(dump_path, "data", "#{table}.json")))
532
- tables_with_counts[table] = data["data"].size
537
+ # Read NDJSON format - each line is a separate JSON chunk
538
+ total_rows = 0
539
+ File.readlines(File.join(dump_path, "data", "#{table}.json")).each do |line|
540
+ chunk = JSON.parse(line.strip)
541
+ total_rows += chunk["data"].size if chunk["data"]
542
+ end
543
+ tables_with_counts[table] = total_rows
533
544
  else
534
545
  tables_with_counts[table] = 0
535
546
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Tapsoob
3
- VERSION = "0.5.27".freeze
3
+ VERSION = "0.5.29".freeze
4
4
  end
@@ -2,7 +2,7 @@ namespace :tapsoob do
2
2
  desc "Pulls a database to your filesystem"
3
3
  task :pull => :environment do
4
4
  # Default options
5
- opts={:default_chunksize => 1000, :debug => false, :resume_filename => nil, :disable_compression => false, :schema => true, :data => true, :indexes_first => false}
5
+ opts={:default_chunksize => 1000, :debug => false, :resume_filename => nil, :disable_compression => false, :schema => true, :data => true, :indexes_first => false, :progress => true}
6
6
 
7
7
  # Get the dump_path
8
8
  dump_path = File.expand_path(Rails.root.join("db", Time.now.strftime("%Y%m%d%I%M%S%p"))).to_s
@@ -23,7 +23,7 @@ namespace :tapsoob do
23
23
  desc "Push a compatible dump on your filesystem to a database"
24
24
  task :push, [:timestamp] => :environment do |t, args|
25
25
  # Default options
26
- opts={:default_chunksize => 1000, :debug => false, :resume_filename => nil, :disable_compression => false, :schema => true, :data => true, :indexes_first => false}
26
+ opts={:default_chunksize => 1000, :debug => false, :resume_filename => nil, :disable_compression => false, :schema => true, :data => true, :indexes_first => false, :progress => true}
27
27
 
28
28
  # Get the dumps
29
29
  dumps = Dir[Rails.root.join("db", "*/")].select { |e| e =~ /([0-9]{14})([A-Z]{2})/ }.sort
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.5.27
4
+ version: 0.5.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Félix Bellanger