blackstack-deployer 1.2.5 → 1.2.10
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/blackstack-deployer.rb +56 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2679af8f481fed33450095920f1df612031cc47f790311e184abe7eed4a9c635
|
4
|
+
data.tar.gz: 53fbd6168caa6fa4b119a54a3533c6472695eb695d11a26f9e2c140656990ebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73e025d6a248f20851a4d40fb635c5a0cc2cecbc4d7d2b4f82e654034923746760daaae6049ead50d0db5db2b1e467bf82af0721b1b4df66a36a5136c4d0c31d
|
7
|
+
data.tar.gz: 56b9cf40e81503d9de69eee618bb1d7cdf024b6604a0fdf00da9da830f75ba5fe7ad4c14c4547cfec26e5b0bb8667e11fe153cb2eae6eb9944089642f80e5b53
|
data/lib/blackstack-deployer.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
require_relative '../../blackstack-nodes/lib/blackstack-nodes'
|
3
|
-
|
1
|
+
require 'blackstack-nodes'
|
4
2
|
require 'sequel'
|
5
3
|
|
6
4
|
module BlackStack
|
@@ -524,6 +522,7 @@ module BlackStack
|
|
524
522
|
end # def
|
525
523
|
|
526
524
|
module DB
|
525
|
+
LOCKFILE = './blackstack-deployer.lock'
|
527
526
|
@@checkpoint = nil
|
528
527
|
@@superhuser = nil
|
529
528
|
@@ndb = nil
|
@@ -532,7 +531,24 @@ module BlackStack
|
|
532
531
|
def self.set_checkpoint(s)
|
533
532
|
@@checkpoint = s
|
534
533
|
end
|
535
|
-
|
534
|
+
|
535
|
+
def self.checkpoint
|
536
|
+
@@checkpoint
|
537
|
+
end
|
538
|
+
|
539
|
+
def self.save_checkpoint
|
540
|
+
File.new('./blackstack-deployer.lock', "w").write(@@checkpoint)
|
541
|
+
end
|
542
|
+
|
543
|
+
def self.load_checkpoint
|
544
|
+
if File.exists?(BlackStack::Deployer::DB::LOCKFILE)
|
545
|
+
@@checkpoint = File.new(BlackStack::Deployer::DB::LOCKFILE, "r").read
|
546
|
+
else
|
547
|
+
@@checkpoint = nil
|
548
|
+
end
|
549
|
+
@@checkpoint
|
550
|
+
end
|
551
|
+
|
536
552
|
def self.connect(s)
|
537
553
|
@@db = Sequel::connect(s)
|
538
554
|
end # def
|
@@ -568,18 +584,36 @@ module BlackStack
|
|
568
584
|
# Reference: https://stackoverflow.com/questions/64066344/import-large-sql-files-with-ruby-sequel-gem
|
569
585
|
# This method is called by `BlackStack::Deployer::db_execute_file` if the filename matches with `/\.sentences\./`.
|
570
586
|
# This method should not be called directly by user code.
|
571
|
-
def self.execute_sentences(sql)
|
587
|
+
def self.execute_sentences(sql, chunk_size=200)
|
572
588
|
tlogger = BlackStack::Deployer::logger
|
573
589
|
|
574
590
|
# Fix issue: Ruby `split': invalid byte sequence in UTF-8 (ArgumentError)
|
575
591
|
# Reference: https://stackoverflow.com/questions/11065962/ruby-split-invalid-byte-sequence-in-utf-8-argumenterror
|
576
|
-
|
577
|
-
|
578
|
-
#
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
592
|
+
#
|
593
|
+
# Fix issue: `PG::SyntaxError: ERROR: at or near "��truncate": syntax error`
|
594
|
+
#
|
595
|
+
sql.encode!('UTF-8', :invalid => :replace, :replace => '')
|
596
|
+
|
597
|
+
# Remove null bytes to avoid error: `String contains null byte`
|
598
|
+
# Reference: https://stackoverflow.com/questions/29320369/coping-with-string-contains-null-byte-sent-from-users
|
599
|
+
sql.gsub!("\u0000", "")
|
600
|
+
|
601
|
+
# Get the array of sentences
|
602
|
+
tlogger.logs "Splitting the sql sentences... "
|
603
|
+
sentences = sql.split(/;/i)
|
604
|
+
tlogger.logf "done (#{sentences.size})"
|
605
|
+
|
606
|
+
# Chunk the array into parts of chunk_size elements
|
607
|
+
# Reference: https://stackoverflow.com/questions/2699584/how-to-split-chunk-a-ruby-array-into-parts-of-x-elements
|
608
|
+
tlogger.logs "Bunlding the array of sentences into chunks of #{chunk_size} each... "
|
609
|
+
chunks = sentences.each_slice(chunk_size).to_a
|
610
|
+
tlogger.logf "done (#{chunks.size})"
|
611
|
+
|
612
|
+
chunk_number = -1
|
613
|
+
chunks.each { |chunk|
|
614
|
+
chunk_number += 1
|
615
|
+
statement = chunk.join(";\n").to_s.strip
|
616
|
+
tlogger.logs "lines #{chunk_size*chunk_number+1} to #{chunk_size*chunk_number+chunk.size} of #{sentences.size}... "
|
583
617
|
begin
|
584
618
|
@@db.execute(statement) #if statement.to_s.strip.size > 0
|
585
619
|
tlogger.done
|
@@ -593,7 +627,7 @@ module BlackStack
|
|
593
627
|
|
594
628
|
# Run a series of `.sql` files with updates to the database.
|
595
629
|
#
|
596
|
-
def self.deploy()
|
630
|
+
def self.deploy(save_checkpoints=false)
|
597
631
|
tlogger = BlackStack::Deployer::logger
|
598
632
|
# get list of `.sql` files in the directory `sql_path`, with a name higher than `last_filename`, sorted by name.
|
599
633
|
Dir.entries(@@folder).select {
|
@@ -606,8 +640,16 @@ module BlackStack
|
|
606
640
|
tlogger.done
|
607
641
|
|
608
642
|
tlogger.logs "Updating checkpoint... "
|
609
|
-
|
643
|
+
BlackStack::Deployer::DB::set_checkpoint filename
|
610
644
|
tlogger.done
|
645
|
+
|
646
|
+
tlogger.logs 'Saving checkpoint... '
|
647
|
+
if save_checkpoints
|
648
|
+
BlackStack::Deployer::DB::save_checkpoint
|
649
|
+
tlogger.done
|
650
|
+
else
|
651
|
+
tlogger.logf 'disabled'
|
652
|
+
end
|
611
653
|
}
|
612
654
|
end # def
|
613
655
|
end # module DB
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blackstack-deployer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: blackstack-nodes
|