prick 0.34.0 → 0.35.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/exe/prick +12 -8
- data/lib/prick/builder/batch.rb +8 -12
- data/lib/prick/builder/builder.rb +33 -12
- data/lib/prick/builder/node.rb +3 -3
- data/lib/prick/builder/parser.rb +53 -53
- data/lib/prick/subcommand/prick-build.rb +2 -2
- data/lib/prick/subcommand/prick-make.rb +2 -2
- data/lib/prick/subcommand/prick-run.rb +26 -22
- data/lib/prick/version.rb +1 -1
- 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: b8acf851da65b094d2abab5a6d9469f20a974732b9e8a8f5bbc4542f72bf8dae
|
4
|
+
data.tar.gz: d7ce7beb146b47aea6f25a93771b206a41434bd2ecbd3a1df33b8580374e29ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b861e5129259bcb0dd384ba7e3c2db09c826cd50105ec514bda309268779e56458a99a3ef8ca1b83226accf7ce6569b957790e5c4374473a3cfb3700ba5ef380
|
7
|
+
data.tar.gz: 6c1b7227ffa63e49825f4acb503d855b9110f18224c1b3f2f7b27b72a92ac0eb3865ea8926470995a71988cb64ab9aa4a5bb26420adafd152364fd31ee28d23a
|
data/exe/prick
CHANGED
@@ -119,19 +119,19 @@ SPEC = %(
|
|
119
119
|
|
120
120
|
TODO
|
121
121
|
|
122
|
-
build! -f,force -t,time --dump=KIND? -- [SCHEMA]
|
122
|
+
build! --step -f,force -t,time --dump=KIND? -- [SCHEMA]
|
123
123
|
Build the project. If SCHEMA is defined, later schemas are excluded. KIND
|
124
124
|
can be 'nodes', 'allnodes' or 'batches' (the default). Schemas marked
|
125
125
|
with 'no refresh' is not built unless the --force is present
|
126
126
|
|
127
|
-
make! -t,time --dump=KIND? -- [SCHEMA]
|
127
|
+
make! --step -t,time --dump=KIND? -- [SCHEMA]
|
128
128
|
@ Only rebuild changed files
|
129
129
|
|
130
130
|
Checks file timestamps against the time of the last build and only
|
131
131
|
rebuild affected parts of the project. KIND can be 'nodes', 'allnodes' or
|
132
132
|
'batches' (the default)
|
133
133
|
|
134
|
-
run! -t,time --dump=KIND? --schema=SCHEMA -- PATH
|
134
|
+
run! --step -t,time --dump=KIND? --schema=SCHEMA -- PATH
|
135
135
|
@ Execute path in Prick environment
|
136
136
|
|
137
137
|
Execute a single directory or file within the Prick environment. If given
|
@@ -361,19 +361,22 @@ begin
|
|
361
361
|
dump = cmd.dump? ? cmd.dump("batches")&.to_sym || :batches : nil
|
362
362
|
# exclude = cmd.exclude? ? cmd.exclude.split(",") : []
|
363
363
|
Prick::SubCommand.build(
|
364
|
-
database, username, args.expect(0..1),
|
364
|
+
database, username, args.expect(0..1),
|
365
|
+
force: cmd.force?, step: cmd.step?, timer: cmd.time?, dump: dump)
|
365
366
|
|
366
367
|
when :make!
|
367
368
|
require_db
|
368
369
|
dump = cmd.dump? ? cmd.dump("batches")&.to_sym || :batches : nil
|
369
|
-
Prick::SubCommand.make(
|
370
|
+
Prick::SubCommand.make(
|
371
|
+
database, username, args.expect(0..1),
|
372
|
+
step: cmd.step?, timer: cmd.time?, dump: dump)
|
370
373
|
|
371
374
|
when :run!
|
372
375
|
require_db
|
373
376
|
dump = cmd.dump? ? cmd.dump("batches")&.to_sym || :batches : nil
|
374
377
|
Prick::SubCommand.run(
|
375
378
|
database, username, args.expect(1),
|
376
|
-
timer: cmd.time?, dump: dump, schema: cmd.schema)
|
379
|
+
step: cmd.step?, timer: cmd.time?, dump: dump, schema: cmd.schema)
|
377
380
|
|
378
381
|
when :bash!
|
379
382
|
Prick::SubCommand.bash(main: cmd.main?)
|
@@ -493,7 +496,8 @@ rescue ShellOpts::Error, Prick::Error => ex
|
|
493
496
|
raise
|
494
497
|
ShellOpts.error(ex.message)
|
495
498
|
|
496
|
-
|
497
|
-
|
499
|
+
# FIXME
|
500
|
+
#rescue RuntimeError, IOError, ShellOpts::Failure, Prick::Failure, Prick::Build::PostgresError => ex
|
501
|
+
# ShellOpts.failure(ex.message)
|
498
502
|
end
|
499
503
|
|
data/lib/prick/builder/batch.rb
CHANGED
@@ -28,7 +28,8 @@ module Prick
|
|
28
28
|
end
|
29
29
|
|
30
30
|
class SqlBatch < BuildBatch
|
31
|
-
def execute
|
31
|
+
def execute
|
32
|
+
# puts "#execute"
|
32
33
|
super {
|
33
34
|
begin
|
34
35
|
sql = []
|
@@ -41,22 +42,16 @@ module Prick
|
|
41
42
|
sql = [node.source]
|
42
43
|
end
|
43
44
|
|
44
|
-
if
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
else
|
50
|
-
node = nil
|
51
|
-
conn.execute sql + nodes[sql.size..-1].map(&:source), silent: true
|
45
|
+
conn.execute sql, silent: true if !sql.empty?
|
46
|
+
for node in nodes # This is marginally faster than concatenating all nodes
|
47
|
+
# puts node.source
|
48
|
+
conn.execute node.source, silent: true
|
52
49
|
end
|
53
50
|
|
54
51
|
rescue PG::Error => ex
|
55
52
|
error, line, char = conn.err
|
56
53
|
file = nil
|
57
|
-
if
|
58
|
-
;
|
59
|
-
elsif line
|
54
|
+
if line
|
60
55
|
# Locate error node and make line number relative
|
61
56
|
if line < nodes.first.lines
|
62
57
|
node = nodes.first
|
@@ -81,6 +76,7 @@ module Prick
|
|
81
76
|
elsif node
|
82
77
|
message = "#{error} from #{node.path}"
|
83
78
|
else
|
79
|
+
raise ArgumentError, "Oops"
|
84
80
|
message = conn.errmsg + " in SQL batch"
|
85
81
|
end
|
86
82
|
raise PostgresError.new(message, file, line, char)
|
@@ -45,6 +45,9 @@ module Prick
|
|
45
45
|
# True if this is a single-file build
|
46
46
|
attr_reader :single
|
47
47
|
|
48
|
+
# True if SQL entries should be single-stepped. Default false
|
49
|
+
attr_reader :step
|
50
|
+
|
48
51
|
# Pool of nodes. Initialized by #load_pool
|
49
52
|
attr_reader :pool
|
50
53
|
|
@@ -55,9 +58,9 @@ module Prick
|
|
55
58
|
:pg_graph_ignore_schemas,
|
56
59
|
:refresh_schemas, :keep_schemas
|
57
60
|
|
58
|
-
def batches() @batches
|
61
|
+
def batches() @batches || create_batches end
|
59
62
|
|
60
|
-
def initialize(conn, path, clean = true, single: false, touched: false)
|
63
|
+
def initialize(conn, path, clean = true, single: false, touched: false, load_pool: true, step: false)
|
61
64
|
File.exist?(path) or raise Error, "Can't find #{path}"
|
62
65
|
single || File.directory?(path) or raise Error, "Can't find directory #{path}"
|
63
66
|
|
@@ -66,14 +69,20 @@ module Prick
|
|
66
69
|
@reflections_file = REFLECTIONS_PATH
|
67
70
|
@clean = clean
|
68
71
|
@single = single
|
69
|
-
@
|
72
|
+
@step = step
|
70
73
|
@root = Parser.parse(conn, path, single: single)
|
71
|
-
|
72
|
-
@batches = nil # Initialized by #
|
74
|
+
@pool = nil # Initialized by #load_pool
|
75
|
+
@batches = nil # Initialized by #create_batches
|
76
|
+
self.load_pool if load_pool
|
77
|
+
end
|
78
|
+
|
79
|
+
def load_pool
|
80
|
+
@pool = NodePool.new
|
81
|
+
load_pool_impl(@root)
|
73
82
|
end
|
74
83
|
|
75
84
|
# Group sources into batches
|
76
|
-
def
|
85
|
+
def create_batches
|
77
86
|
@batches = []
|
78
87
|
kind = nil
|
79
88
|
batch = nil
|
@@ -88,8 +97,11 @@ module Prick
|
|
88
97
|
when :exe # Exe sources always create a new batch
|
89
98
|
@batches << batch if batch
|
90
99
|
batch = SqlBatch.new(self)
|
91
|
-
when batch&.kind
|
92
|
-
|
100
|
+
when batch&.kind # Same kind as current batch
|
101
|
+
if node.kind == :sql && step
|
102
|
+
@batches << batch if batch
|
103
|
+
batch = SqlBatch.new(self)
|
104
|
+
end
|
93
105
|
when :sql || node.kind == :inline
|
94
106
|
if batch&.kind != :exe
|
95
107
|
@batches << batch if batch
|
@@ -108,13 +120,17 @@ module Prick
|
|
108
120
|
end
|
109
121
|
batch.nodes << node
|
110
122
|
end
|
111
|
-
|
112
123
|
@batches << batch if batch
|
124
|
+
|
125
|
+
@batches
|
113
126
|
end
|
114
127
|
|
115
128
|
def execute(conn, create_schemas: schemas)
|
129
|
+
# Load pool
|
130
|
+
load_pool if pool.nil?
|
131
|
+
|
116
132
|
# Group batches
|
117
|
-
|
133
|
+
create_batches if batches.nil?
|
118
134
|
|
119
135
|
# Register build in database
|
120
136
|
Prick.state.save_build_begin
|
@@ -124,6 +140,10 @@ module Prick
|
|
124
140
|
|
125
141
|
# Execute batch groups
|
126
142
|
t0 = Time.now
|
143
|
+
# for batch in batches
|
144
|
+
# puts "Executing #{batch.class} batch"
|
145
|
+
# batch.execute
|
146
|
+
# end
|
127
147
|
batches.each(&:execute)
|
128
148
|
t1 = Time.now
|
129
149
|
|
@@ -133,15 +153,16 @@ module Prick
|
|
133
153
|
end
|
134
154
|
|
135
155
|
def dump
|
156
|
+
load_pool if pool.nil?
|
136
157
|
batches ? batches.each(&:dump) : pool.dump
|
137
158
|
end
|
138
159
|
|
139
160
|
private
|
140
|
-
def
|
161
|
+
def load_pool_impl(build_node)
|
141
162
|
pool.add(build_node.init_nodes)
|
142
163
|
build_node.decl_nodes.each { |node|
|
143
164
|
pool.add node
|
144
|
-
|
165
|
+
load_pool_impl(node) if node.kind == :yml
|
145
166
|
}
|
146
167
|
pool.add(build_node.seed_nodes)
|
147
168
|
pool.add(build_node.term_nodes)
|
data/lib/prick/builder/node.rb
CHANGED
@@ -11,7 +11,7 @@ module Prick
|
|
11
11
|
def name() @name = File.basename(path) end
|
12
12
|
|
13
13
|
# Note that schema defaults to 'public' which may not be what you want in
|
14
|
-
#
|
14
|
+
# some cases
|
15
15
|
def schema() @schema ||= parent&.schema || "public" end
|
16
16
|
def schema=(s) @schema = s end
|
17
17
|
|
@@ -46,7 +46,7 @@ module Prick
|
|
46
46
|
|
47
47
|
def to_s() @to_s ||= [path, args].compact.join(" ") end
|
48
48
|
def inspect() to_s end
|
49
|
-
def dump() puts "#{inspect} (#{schema})" end
|
49
|
+
def dump() puts "#{inspect} (#{@schema || 'nil'})" end
|
50
50
|
|
51
51
|
protected
|
52
52
|
def read_source
|
@@ -194,7 +194,7 @@ module Prick
|
|
194
194
|
puts "BuildNode #{path}"
|
195
195
|
indent {
|
196
196
|
puts "has_schema: #{has_schema}"
|
197
|
-
puts "schema: #{schema}"
|
197
|
+
puts "schema: #{@schema || 'nil'}"
|
198
198
|
puts "refresh: #{refresh_schema.to_s}"
|
199
199
|
puts "pg_graph_ignore_schema: #{pg_graph_ignore_schema}"
|
200
200
|
decl_nodes.each(&:dump)
|
data/lib/prick/builder/parser.rb
CHANGED
@@ -25,7 +25,6 @@ module Prick
|
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
|
-
|
29
28
|
# First built unit is a RootBuildNode, the rest are regular BuildNode objects
|
30
29
|
def make_build_unit(parent, path)
|
31
30
|
if @unit
|
@@ -35,62 +34,13 @@ module Prick
|
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
#
|
40
|
-
# Note that "." is ignored in the search path
|
41
|
-
def find_executable(filename) # ChatGPT
|
42
|
-
Prick.state.executable_search_path.split(File::PATH_SEPARATOR).each do |directory|
|
43
|
-
next if directory == "."
|
44
|
-
path = File.join(directory, filename)
|
45
|
-
return path if File.file?(path) && File.executable?(path)
|
46
|
-
end
|
47
|
-
nil
|
48
|
-
end
|
49
|
-
|
50
|
-
# Expand environment variables in the given file name
|
51
|
-
#
|
52
|
-
# #expend_filename substitute '$<variable>' expressions in the filename
|
53
|
-
# with the corresponding value in the current environment. If the file
|
54
|
-
# was not found, inherited environments are processed hierarchly with the
|
55
|
-
# special environment variable ENVIRONMENT set to each PRICK_ENVIRONMENT
|
56
|
-
# value in the inherited environments
|
57
|
-
#
|
58
|
-
# Return the resulting path to the file and nil if not found
|
59
|
-
#
|
60
|
-
def expand_filename(dir, filename)
|
61
|
-
envs = Prick.state.environments
|
62
|
-
env = envs[Prick.state.environment]
|
63
|
-
bash_vars = Prick.state.bash_environment.dup
|
64
|
-
|
65
|
-
last = nil
|
66
|
-
for env in [env] + env.ancestors.reverse
|
67
|
-
bash_vars["ENVIRONMENT"] = env.name
|
68
|
-
file = expand_variables(filename, bash_vars)
|
69
|
-
# last ||= (file != last and file) or return nil # return if no ENVIRONMENT substitution
|
70
|
-
path = (file.start_with?("/") ? file : File.join(dir, file))
|
71
|
-
|
72
|
-
# Check for file (may be executable)
|
73
|
-
return path if File.exist?(path)
|
74
|
-
|
75
|
-
# Check for executable in search path if file doesn't contain a '/'
|
76
|
-
path = find_executable(file) and return path if file !~ /\//
|
77
|
-
end
|
78
|
-
|
79
|
-
# Return nil if not found
|
80
|
-
return nil
|
81
|
-
end
|
82
|
-
|
83
|
-
# Expand $ENVIRONMENT variable
|
84
|
-
def expand_string(string)
|
85
|
-
expand_variables(string, Prick.state.bash_environment)
|
86
|
-
end
|
87
|
-
|
88
|
-
def parse_path(path)
|
37
|
+
def parse_path(path, schema: nil)
|
89
38
|
File.exist?(path) or raise Error, "Can't find #{file}"
|
90
39
|
dir = File.dirname(path)
|
91
40
|
file = File.basename(path)
|
92
41
|
unit = make_build_unit(nil, nil)
|
93
|
-
|
42
|
+
unit.schema = schema if schema
|
43
|
+
entry = parse_build_entry(unit, dir, file)
|
94
44
|
unit
|
95
45
|
end
|
96
46
|
|
@@ -211,6 +161,56 @@ module Prick
|
|
211
161
|
end
|
212
162
|
end
|
213
163
|
end
|
164
|
+
|
165
|
+
# Search for an executable in path. Return nil if not found
|
166
|
+
#
|
167
|
+
# Note that "." is ignored in the search path
|
168
|
+
def find_executable(filename) # ChatGPT
|
169
|
+
Prick.state.executable_search_path.split(File::PATH_SEPARATOR).each do |directory|
|
170
|
+
next if directory == "."
|
171
|
+
path = File.join(directory, filename)
|
172
|
+
return path if File.file?(path) && File.executable?(path)
|
173
|
+
end
|
174
|
+
nil
|
175
|
+
end
|
176
|
+
|
177
|
+
# Expand environment variables in the given file name
|
178
|
+
#
|
179
|
+
# #expend_filename substitute '$<variable>' expressions in the filename
|
180
|
+
# with the corresponding value in the current environment. If the file
|
181
|
+
# was not found, inherited environments are processed hierarchly with the
|
182
|
+
# special environment variable ENVIRONMENT set to each PRICK_ENVIRONMENT
|
183
|
+
# value in the inherited environments
|
184
|
+
#
|
185
|
+
# Return the resulting path to the file and nil if not found
|
186
|
+
#
|
187
|
+
def expand_filename(dir, filename)
|
188
|
+
envs = Prick.state.environments
|
189
|
+
env = envs[Prick.state.environment]
|
190
|
+
bash_vars = Prick.state.bash_environment.dup
|
191
|
+
|
192
|
+
last = nil
|
193
|
+
for env in [env] + env.ancestors.reverse
|
194
|
+
bash_vars["ENVIRONMENT"] = env.name
|
195
|
+
file = expand_variables(filename, bash_vars)
|
196
|
+
# last ||= (file != last and file) or return nil # return if no ENVIRONMENT substitution
|
197
|
+
path = (file.start_with?("/") ? file : File.join(dir, file))
|
198
|
+
|
199
|
+
# Check for file (may be executable)
|
200
|
+
return path if File.exist?(path)
|
201
|
+
|
202
|
+
# Check for executable in search path if file doesn't contain a '/'
|
203
|
+
path = find_executable(file) and return path if file !~ /\//
|
204
|
+
end
|
205
|
+
|
206
|
+
# Return nil if not found
|
207
|
+
return nil
|
208
|
+
end
|
209
|
+
|
210
|
+
# Expand $ENVIRONMENT variable
|
211
|
+
def expand_string(string)
|
212
|
+
expand_variables(string, Prick.state.bash_environment)
|
213
|
+
end
|
214
214
|
end
|
215
215
|
end
|
216
216
|
end
|
@@ -7,7 +7,7 @@ module Prick::SubCommand
|
|
7
7
|
database, username, schema,
|
8
8
|
builddir: Prick.state.schema_dir,
|
9
9
|
force: false, # Build all schemas
|
10
|
-
timer: nil, dump: nil)
|
10
|
+
step: false, timer: nil, dump: nil)
|
11
11
|
|
12
12
|
Timer.on! if timer
|
13
13
|
|
@@ -30,7 +30,7 @@ module Prick::SubCommand
|
|
30
30
|
end
|
31
31
|
conn = Prick.state.connection
|
32
32
|
|
33
|
-
builder = Prick::Build::Builder.new(conn, builddir)
|
33
|
+
builder = Prick::Build::Builder.new(conn, builddir, step: step)
|
34
34
|
|
35
35
|
if exist # Empty (part of) the database
|
36
36
|
if force
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative '../builder/builder.rb'
|
4
4
|
|
5
5
|
module Prick::SubCommand
|
6
|
-
def self.make(database, username, schema, timer: nil, dump: nil)
|
6
|
+
def self.make(database, username, schema, step: false, timer: nil, dump: nil)
|
7
7
|
Timer.on! if timer
|
8
8
|
Timer.time "Prick::Command#make" do
|
9
9
|
begin
|
@@ -26,7 +26,7 @@ module Prick::SubCommand
|
|
26
26
|
clean = true
|
27
27
|
end
|
28
28
|
|
29
|
-
builder = Prick::Build::Builder.new(conn, "schema", clean)
|
29
|
+
builder = Prick::Build::Builder.new(conn, "schema", clean, step: step)
|
30
30
|
|
31
31
|
if schema
|
32
32
|
after_schemas = builder.pool.after_schema(schema)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative '../builder/builder.rb'
|
4
4
|
|
5
5
|
module Prick::SubCommand
|
6
|
-
def self.run(database, username, path, timer: nil, dump: nil, schema: nil)
|
6
|
+
def self.run(database, username, path, step: false, timer: nil, dump: nil, schema: nil)
|
7
7
|
|
8
8
|
Timer.on! if timer
|
9
9
|
|
@@ -27,7 +27,7 @@ module Prick::SubCommand
|
|
27
27
|
conn = Prick.state.connection
|
28
28
|
|
29
29
|
# Parse
|
30
|
-
builder = Prick::Build::Builder.new(conn, path, single: true)
|
30
|
+
builder = Prick::Build::Builder.new(conn, path, single: true, load_pool: false, step: step)
|
31
31
|
|
32
32
|
# Register if a build file is referenced and normalize path to
|
33
33
|
# include build.yml of directories
|
@@ -43,9 +43,7 @@ module Prick::SubCommand
|
|
43
43
|
# Read schema from build file if possible and decide if schema should
|
44
44
|
# be dropped beforehand
|
45
45
|
if is_build_file
|
46
|
-
|
47
|
-
build_node = pool.all_nodes.first
|
48
|
-
if build_node.has_schema
|
46
|
+
if builder.root.has_schema
|
49
47
|
!schema or Prick.error "Can't use --schema when doing a schema build"
|
50
48
|
is_schema_rebuild = true
|
51
49
|
schema = build_node.schema
|
@@ -67,6 +65,9 @@ module Prick::SubCommand
|
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
68
|
+
# Write-back schema to builder
|
69
|
+
builder.root.schema = schema
|
70
|
+
|
70
71
|
# Drop schema if needed
|
71
72
|
if is_schema_rebuild
|
72
73
|
conn.schema.drop schema, cascade: true
|
@@ -78,26 +79,29 @@ module Prick::SubCommand
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
if dump
|
83
|
+
builder.load_pool
|
84
|
+
case dump
|
85
|
+
when :nodes; builder.nodes.reject { |node| node.is_a?(Build::BuildNode) }.map &:dump
|
86
|
+
when :allnodes; builder.nodes.map &:dump
|
87
|
+
when :batches; builder.dump
|
88
|
+
else
|
89
|
+
Prick.error "Illegal dump type: #{dump.inspect}"
|
90
|
+
end
|
86
91
|
else
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
Timer.time "Execute build object" do
|
91
|
-
builder.execute conn
|
92
|
+
Timer.time "Execute build object" do
|
93
|
+
builder.execute conn
|
94
|
+
end
|
92
95
|
end
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
# FIXME
|
98
|
+
# rescue Prick::Error => ex
|
99
|
+
# $stderr.puts ex.message
|
100
|
+
# exit 1
|
101
|
+
#
|
102
|
+
# rescue ::Command::Error => ex
|
103
|
+
# $stderr.puts ex.message
|
104
|
+
# exit 1
|
101
105
|
|
102
106
|
ensure
|
103
107
|
super_conn&.terminate
|
data/lib/prick/version.rb
CHANGED