rumination 0.3.1 → 0.4.0
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/rumination/pg/commands.rb +18 -0
- data/lib/rumination/pg/restore.rb +67 -0
- data/lib/rumination/pg.rb +1 -0
- data/lib/rumination/version.rb +1 -1
- data/lib/rumination.rb +4 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3796abee1e89f550d0afc421dbfb7cbf6e9398ca
|
4
|
+
data.tar.gz: 0099071ff01dfa452b382c4425df6b6afc9eca3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84ef7e03718acca0806c0c1822489746a4a2a898ee826a9cb3f61ef40902b24ce36e4c5f5a7af9dbf24a2b2efe54d0fbae730a3c3119c773f90790683485a24f
|
7
|
+
data.tar.gz: b3b1466d3ea9e39671f47c4ff4a187972aa89155fcb73ea05fdbc4a8785910030e5df1cd24f5cf01b8c3f8f219770c36d359710f72ba9068ec8eee075f70a70b
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Rumination
|
2
|
+
module Pg
|
3
|
+
# include this module into something with #sh, e.g. next to Rake::FileUtils
|
4
|
+
module Commands
|
5
|
+
def pg_dump *args
|
6
|
+
sh "pg_dump #{args.join(" ")}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def pg_restore *args
|
10
|
+
Pg::Restore.call *args, "-d", ENV["PGDATABASE"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def rsync *args
|
14
|
+
sh "rsync #{args.join(" ")}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Rumination
|
2
|
+
module Pg
|
3
|
+
class Restore
|
4
|
+
attr_reader :args
|
5
|
+
|
6
|
+
def initialize *args
|
7
|
+
@args = @args.dup.freeze
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.call *args
|
11
|
+
new(*args).call
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
command = "pg_restore #{args.join(" ")}"
|
16
|
+
puts command
|
17
|
+
Open3.popen3 ENV, command do |stdin, stdout, stderr, thread|
|
18
|
+
out_lines = stdout.readlines
|
19
|
+
err_lines = stderr.readlines
|
20
|
+
save_stream :stdout, out_lines
|
21
|
+
save_stream :stderr, err_lines
|
22
|
+
puts_log out_lines + err_lines, indent: 2
|
23
|
+
analyse_stderr! err_lines
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def puts_log lines, indent: 0
|
30
|
+
lines = lines.dup
|
31
|
+
lines[3..-4] = ["", "... snip snip ...", ""] unless lines.count < 8
|
32
|
+
lines.each do |line|
|
33
|
+
puts line.indent(indent)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def analyse_stderr! lines
|
38
|
+
text = lines.join("\n")
|
39
|
+
error_count = text.scan(/ERROR/).count
|
40
|
+
more_errors_than_ignored = error_count > 0 && !expected_errors?(text, error_count)
|
41
|
+
other_errors = error_matchers.any?{|m| m === text}
|
42
|
+
if more_errors_than_ignored || other_errors
|
43
|
+
raise RuntimeError, "pg_restore seems to have failed"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def save_stream name, lines
|
48
|
+
File.open("log/pg_restore.#{name}.log","w") do |io|
|
49
|
+
io.puts lines
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def save_streams out_lines, err_lines
|
54
|
+
end
|
55
|
+
|
56
|
+
def error_matchers
|
57
|
+
[
|
58
|
+
/could not open input file/
|
59
|
+
]
|
60
|
+
end
|
61
|
+
|
62
|
+
def expected_errors? text, count
|
63
|
+
text =~ /WARNING: errors ignored on restore: #{count}/
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "pg/commands"
|
data/lib/rumination/version.rb
CHANGED
data/lib/rumination.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Baguinski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,9 @@ files:
|
|
84
84
|
- bin/setup
|
85
85
|
- lib/rumination.rb
|
86
86
|
- lib/rumination/dev_user.rb
|
87
|
+
- lib/rumination/pg.rb
|
88
|
+
- lib/rumination/pg/commands.rb
|
89
|
+
- lib/rumination/pg/restore.rb
|
87
90
|
- lib/rumination/version.rb
|
88
91
|
- rumination.gemspec
|
89
92
|
homepage: https://github.com/artm/rumination
|