alterity 1.3.1 → 1.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/alterity.rb +3 -0
- data/lib/alterity/configuration.rb +4 -5
- data/lib/alterity/version.rb +1 -1
- data/spec/bin/custom_config.rb +13 -0
- data/spec/bin/test_custom_config_result.rb +20 -1
- 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: bf1aafe98960046d356a7f82baa19dca7a2160ec58fa48a93da12ebd12794d16
|
4
|
+
data.tar.gz: 4793526689c37e33673aab4e0a8b570445fd78b369c0edbe382cf9e9aa078a97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dfad0d6f235e3fb8da9cc0074015298261532d9f1da903cc47d73fb776d13c6efe77c7847f59f4be2286292240a2473165b8e7b756c41a1935691b13e8db10a
|
7
|
+
data.tar.gz: b931b6805769dcc0ae2c9fbeddb25036e3aca3cb8bb1ad194a3b5265fb7ae9fc895f43223b3b5409e7367db69ff40f07dff5bc881bc294733e220f66abe9ddad
|
data/lib/alterity.rb
CHANGED
@@ -52,6 +52,7 @@ class Alterity
|
|
52
52
|
alter_argument = %("#{updates.gsub('"', '\\"').gsub('`', '\\\`')}")
|
53
53
|
prepared_command = config.command.call(altered_table, alter_argument).to_s.gsub(/\n/, "\\\n")
|
54
54
|
puts "[Alterity] Will execute: #{prepared_command}"
|
55
|
+
config.before_command&.call(prepared_command)
|
55
56
|
|
56
57
|
result_str = +""
|
57
58
|
exit_status = nil
|
@@ -59,8 +60,10 @@ class Alterity
|
|
59
60
|
stdout_and_stderr.each do |line|
|
60
61
|
puts line
|
61
62
|
result_str << line
|
63
|
+
config.on_command_output&.call(line)
|
62
64
|
end
|
63
65
|
exit_status = wait_thr.value
|
66
|
+
config.after_command&.call(wait_thr.value.to_i)
|
64
67
|
end
|
65
68
|
|
66
69
|
raise("[Alterity] Command failed. Full output: #{result_str}") unless exit_status.success?
|
@@ -4,7 +4,10 @@ class Alterity
|
|
4
4
|
Configuration = Struct.new(
|
5
5
|
:command,
|
6
6
|
:host, :port, :database, :username, :password,
|
7
|
-
:replicas_dsns_database, :replicas_dsns_table, :replicas_dsns
|
7
|
+
:replicas_dsns_database, :replicas_dsns_table, :replicas_dsns,
|
8
|
+
:before_command,
|
9
|
+
:on_command_output,
|
10
|
+
:after_command
|
8
11
|
)
|
9
12
|
CurrentState = Struct.new(:migrating, :disabled)
|
10
13
|
cattr_accessor :state
|
@@ -36,10 +39,6 @@ class Alterity
|
|
36
39
|
yield config
|
37
40
|
end
|
38
41
|
|
39
|
-
def command=(new_command)
|
40
|
-
config.command = new_command
|
41
|
-
end
|
42
|
-
|
43
42
|
def disable
|
44
43
|
state.disabled = true
|
45
44
|
yield
|
data/lib/alterity/version.rb
CHANGED
data/spec/bin/custom_config.rb
CHANGED
@@ -8,6 +8,7 @@ Alterity.configure do |config|
|
|
8
8
|
system("echo '#{string}' > /tmp/custom_command_result.txt")
|
9
9
|
system("echo '#{altered_table}' >> /tmp/custom_command_result.txt")
|
10
10
|
system("echo '#{alter_argument}' >> /tmp/custom_command_result.txt")
|
11
|
+
"ls /"
|
11
12
|
}
|
12
13
|
|
13
14
|
config.replicas(
|
@@ -23,4 +24,16 @@ Alterity.configure do |config|
|
|
23
24
|
"h=#{ENV['MYSQL_HOST']}"
|
24
25
|
]
|
25
26
|
)
|
27
|
+
|
28
|
+
config.before_command = lambda do |command|
|
29
|
+
File.new("/tmp/before_command.txt", "w").syswrite(command)
|
30
|
+
end
|
31
|
+
|
32
|
+
config.on_command_output = lambda do |output|
|
33
|
+
File.new("/tmp/on_command_output.txt", "w+").syswrite(output)
|
34
|
+
end
|
35
|
+
|
36
|
+
config.after_command = lambda do |exit_status|
|
37
|
+
File.new("/tmp/after_command.txt", "w").syswrite(exit_status)
|
38
|
+
end
|
26
39
|
end
|
@@ -15,6 +15,25 @@ puts result
|
|
15
15
|
p result.chars.map(&:hex)
|
16
16
|
|
17
17
|
if result != expected_result
|
18
|
-
puts "=>
|
18
|
+
puts "=> mismatched result"
|
19
|
+
exit(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
result = File.read("/tmp/before_command.txt")
|
24
|
+
if result != "ls /"
|
25
|
+
puts "=> mismatched before_command"
|
26
|
+
exit(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
result = File.read("/tmp/on_command_output.txt")
|
30
|
+
if !result.include?("var")
|
31
|
+
puts "=> mismatched on_command_output"
|
32
|
+
exit(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
result = File.read("/tmp/after_command.txt")
|
36
|
+
if result.strip != "0"
|
37
|
+
puts "=> mismatched after_command"
|
19
38
|
exit(1)
|
20
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alterity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Maximin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|