prick 0.14.0 → 0.18.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/TODO +3 -0
- data/exe/prick +1 -1
- data/lib/prick/builder.rb +34 -10
- data/lib/prick/command.rb +13 -4
- data/lib/prick/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22580f7a2f37e4ad59c6354e3b6ac1d7bb6f5eb7fe8f44eddb941ba715f8fa39
|
4
|
+
data.tar.gz: b0b5bf43389a0e35c6a739b92b4e50b043cb75ab1e215aa109a9a68e4f17e1e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7768a47145ae07f6ae99e808ad513107ccd98327fc009311cd0bfde1f1dbd3a52a3d9f5061c6bb3918b12da6850b0cf4e5242efade679d950a603047c8dd9cfc
|
7
|
+
data.tar.gz: e2709800fe62d599bba1ea64960b4a09e8a97a87da3d60731e8293f4957c9ac35147122dea16220481b9c49b17d3cf31377663f1328b99608c0fc3cc84ca4ad9
|
data/TODO
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
|
2
|
+
o Add a top-level 'global' directory for stuff that doesn't belong to a schema or that
|
3
|
+
require superuser privileges. prick-build should then execute the content of that
|
4
|
+
directory first before switching to the database user
|
2
5
|
o Check for commits to tags
|
3
6
|
o Accumulate version history in prick.versions instead of just having the newest
|
4
7
|
o Using rc's in migration syntax: fork-version-fork-version.rc1 ?
|
data/exe/prick
CHANGED
@@ -198,7 +198,7 @@ begin
|
|
198
198
|
# Change to parent directory containing the Prick version file if not found
|
199
199
|
# in the current directory
|
200
200
|
program.current_directory = Dir.getwd
|
201
|
-
while
|
201
|
+
while Dir.getwd != "/" && !File.exist?(PRICK_VERSION_FILE)
|
202
202
|
Dir.chdir("..")
|
203
203
|
end
|
204
204
|
|
data/lib/prick/builder.rb
CHANGED
@@ -19,7 +19,7 @@ module Prick
|
|
19
19
|
# When a resource match a directory, the directory can contain a special
|
20
20
|
# default resource ('build' or 'migrate') that takes over the rest of the
|
21
21
|
# build process for that directory. Typically, you'll use the 'build.yml' or
|
22
|
-
# 'migrate.yml' to control the build order of the other resources If a
|
22
|
+
# 'migrate.yml' to control the build order of the other resources. If a
|
23
23
|
# directory doesn't contain a build resource, the resources in the directory
|
24
24
|
# are built in alphabetic order
|
25
25
|
#
|
@@ -38,6 +38,7 @@ module Prick
|
|
38
38
|
@default = default
|
39
39
|
@execute = true
|
40
40
|
@lines = []
|
41
|
+
@cwd = Dir.getwd # used in error messages
|
41
42
|
end
|
42
43
|
|
43
44
|
def build(subject = default, execute: true)
|
@@ -59,6 +60,7 @@ module Prick
|
|
59
60
|
|
60
61
|
protected
|
61
62
|
def do_dir(path, &block)
|
63
|
+
# puts "do_dir(#{path.inspect})"
|
62
64
|
dir, file = File.split(path)
|
63
65
|
Dir.chdir(dir) { yield(file) }
|
64
66
|
end
|
@@ -67,7 +69,13 @@ module Prick
|
|
67
69
|
# puts "do_sql(#{path})"
|
68
70
|
do_dir(path) { |file|
|
69
71
|
if @execute
|
70
|
-
|
72
|
+
begin
|
73
|
+
Rdbms.exec_file(database.name, file, user: database.user, schema: schema)
|
74
|
+
rescue Command::Error => ex
|
75
|
+
$stderr.puts ex.stderr
|
76
|
+
$stderr.puts "in #{reldir}/#{file}"
|
77
|
+
exit 1
|
78
|
+
end
|
71
79
|
else
|
72
80
|
@lines += IO.readlines(file).map(&:chomp)
|
73
81
|
end
|
@@ -75,12 +83,19 @@ module Prick
|
|
75
83
|
true
|
76
84
|
end
|
77
85
|
|
78
|
-
def do_exe(path, schema: nil)
|
79
|
-
# puts "do_exe(#{path})"
|
86
|
+
def do_exe(path, args = [], schema: nil)
|
87
|
+
# puts "do_exe(#{path.inspect}, #{args.inspect})"
|
80
88
|
do_dir(path) { |file|
|
81
|
-
|
89
|
+
cmd = (["./#{file}"] + args).join(" ")
|
90
|
+
lines = Command.command cmd, stdin: [database.name, database.user]
|
82
91
|
if @execute
|
83
|
-
|
92
|
+
begin
|
93
|
+
Rdbms.exec_sql(database.name, lines.join("\n"), user: database.user, schema: schema)
|
94
|
+
rescue Command::Error => ex
|
95
|
+
$stderr.puts ex.stderr
|
96
|
+
$stderr.puts "from #{reldir}/#{file}"
|
97
|
+
exit 1
|
98
|
+
end
|
84
99
|
else
|
85
100
|
@lines += lines
|
86
101
|
end
|
@@ -97,8 +112,9 @@ module Prick
|
|
97
112
|
|
98
113
|
# A subject can be both an abstract subject or a concrete file (*.yml, *.sql)
|
99
114
|
def build_subject(subject)
|
100
|
-
|
101
|
-
|
115
|
+
cmd, *args = subject.split(/\s+/)
|
116
|
+
if File.file?(cmd) && File.executable?(cmd)
|
117
|
+
do_exe(cmd, args)
|
102
118
|
elsif File.file?(subject) && subject.end_with?(".yml")
|
103
119
|
do_yml(subject)
|
104
120
|
elsif File.file?(subject) && subject.end_with?(".sql")
|
@@ -130,6 +146,14 @@ module Prick
|
|
130
146
|
end
|
131
147
|
}
|
132
148
|
end
|
149
|
+
|
150
|
+
private
|
151
|
+
# Return the relative path to the current directory from the directory of
|
152
|
+
# the time of the instantiation of the Builder object. Used in error
|
153
|
+
# messages
|
154
|
+
def reldir
|
155
|
+
Dir.getwd.sub(/^#{@cwd}\//, "")
|
156
|
+
end
|
133
157
|
end
|
134
158
|
|
135
159
|
class MigrationBuilder < Builder
|
@@ -172,9 +196,9 @@ module Prick
|
|
172
196
|
super(path, schema: schema)
|
173
197
|
end
|
174
198
|
|
175
|
-
def do_exe(path)
|
199
|
+
def do_exe(path, args = [])
|
176
200
|
schema = Dir.getwd.sub(/^.*schema\/([^\/]+)(?:\/.*)?$/, '\1')
|
177
|
-
super(path, schema: schema)
|
201
|
+
super(path, args, schema: schema)
|
178
202
|
end
|
179
203
|
end
|
180
204
|
end
|
data/lib/prick/command.rb
CHANGED
@@ -15,14 +15,17 @@ module Command
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Execute the shell command 'cmd' and return standard output as an array of
|
18
|
-
# strings
|
18
|
+
# strings. while stderr is passed through unless stderr: is false. If stderr:
|
19
19
|
# is true, it returns a tuple of [stdout, stderr] instead. The shell command
|
20
20
|
# is executed with the `errexit` and `pipefail` bash options
|
21
|
+
#
|
22
|
+
# The :stdin option is a line or an array of lines that'll be fed to the
|
23
|
+
# standard input of the command. Default is nil
|
21
24
|
#
|
22
25
|
# It raises a Command::Error exception if the command fails unless :fail is
|
23
26
|
# true. The exit status of the last command is stored in ::status
|
24
27
|
#
|
25
|
-
def command(cmd, stderr: false, fail: true)
|
28
|
+
def command(cmd, stdin: nil, stderr: false, fail: true)
|
26
29
|
cmd = "set -o errexit\nset -o pipefail\n#{cmd}"
|
27
30
|
|
28
31
|
pw = IO::pipe # pipe[0] for read, pipe[1] for write
|
@@ -52,12 +55,18 @@ module Command
|
|
52
55
|
pr[1].close
|
53
56
|
pe[1].close
|
54
57
|
|
58
|
+
if stdin
|
59
|
+
pw[1].puts(stdin)
|
60
|
+
pw[1].flush
|
61
|
+
pw[1].close
|
62
|
+
end
|
63
|
+
|
55
64
|
@status = Process.waitpid2(pid)[1].exitstatus
|
56
65
|
|
57
66
|
out = pr[0].readlines.collect { |line| line.chop }
|
58
|
-
err = pe[0].readlines.collect { |line| line.chop }
|
67
|
+
err = pe[0].readlines.collect { |line| line.chop }.grep_v(/^NOTICE:/)
|
59
68
|
|
60
|
-
pw[1].close
|
69
|
+
pw[1].close if !stdin
|
61
70
|
pr[0].close
|
62
71
|
pe[0].close
|
63
72
|
|
data/lib/prick/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shellopts
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
- !ruby/object:Gem::Version
|
156
156
|
version: '0'
|
157
157
|
requirements: []
|
158
|
-
rubygems_version: 3.1.
|
158
|
+
rubygems_version: 3.1.4
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: A release control and management system for postgresql
|