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 +4 -4
- data/lib/tapsoob/operation.rb +19 -8
- data/lib/tapsoob/version.rb +1 -1
- data/lib/tasks/tapsoob.rake +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 748c9cf97135cae0c72f0ba298f7c3f197e65764ce4c44c0670d8ef2fe5181ed
|
|
4
|
+
data.tar.gz: 7bebc431915dcf8dd5bff0ee341cf22765646d1854485c23f80b5b9c642fc142
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 404478581e61ebdd2875c21d0af865acd5e9dba010292819046cd5e195c9c78cad675bdd50216ea26c5bba8923c0e532a8bd2593b4fe7eb0e71f85db865ef067
|
|
7
|
+
data.tar.gz: 3310489ebd6dcfd7efc76c4fd5d9b2ec6ffa9da12c6cb4161ffd02267f376927b957f5142dcf42ba81fd544c470c36e07f7e0263b66bcae6168b6c9dfe309b61
|
data/lib/tapsoob/operation.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
532
|
-
|
|
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
|
data/lib/tapsoob/version.rb
CHANGED
data/lib/tasks/tapsoob.rake
CHANGED
|
@@ -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
|