prick 0.39.5 → 0.39.6
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 +14 -14
- data/lib/prick/builder/batch.rb +5 -5
- data/lib/prick/builder/builder.rb +2 -2
- data/lib/prick/builder/node.rb +4 -4
- data/lib/prick/builder/node_pool.rb +5 -5
- data/lib/prick/builder/parser.rb +2 -2
- data/lib/prick/constants.rb +1 -1
- data/lib/prick/diff.rb +1 -1
- data/lib/prick/environment.rb +8 -8
- data/lib/prick/local/fmt.rb +2 -2
- data/lib/prick/local/git.rb +20 -20
- data/lib/prick/local/timer.rb +3 -3
- data/lib/prick/prick_version.rb +4 -4
- data/lib/prick/share/init/prick.yml +4 -4
- data/lib/prick/share/init/schema/prick/build.yml +1 -1
- data/lib/prick/share/init/schema/prick/tables.sql +1 -1
- data/lib/prick/state.rb +15 -15
- data/lib/prick/subcommand/prick-build.rb +4 -4
- data/lib/prick/subcommand/prick-create.rb +3 -3
- data/lib/prick/subcommand/prick-drop.rb +3 -3
- data/lib/prick/subcommand/prick-fox.rb +1 -1
- data/lib/prick/subcommand/prick-init.rb +1 -1
- data/lib/prick/subcommand/prick-list.rb +9 -9
- data/lib/prick/subcommand/prick-make.rb +3 -3
- data/lib/prick/subcommand/prick-run.rb +2 -2
- data/lib/prick/version.rb +1 -1
- data/lib/prick.rb +4 -4
- 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: 75169887ecaae27780bfc25f2aeb21c4f83362c698f855033eacfb02768b1fbd
|
|
4
|
+
data.tar.gz: 23fa69d844aab5f9c1d9198d9ca5c016d96729e5fd6ad884438364b653384e10
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da581962a6423ee34d43cc879c718350d1b02bc963efba126037d98f598664f9570c1bff8dccd38372c0e0b162bf3bb8a0e6fe7cd2e1a2fbe32d955a4a6a1695
|
|
7
|
+
data.tar.gz: 3c135facadbffa2c1c4b8a5f348d4b78584d01657d6c543d5c5453a3fc4f6b4cfc6f29de259df279ec4c4b16bf4f84681db055fdb13b63339d17e5460871e491
|
data/exe/prick
CHANGED
|
@@ -191,7 +191,7 @@ SPEC = %(
|
|
|
191
191
|
List variables for the current environment
|
|
192
192
|
|
|
193
193
|
dump.migration! --force -- VERSION
|
|
194
|
-
|
|
194
|
+
|
|
195
195
|
dump.type!
|
|
196
196
|
Dumps a PgGraph object
|
|
197
197
|
|
|
@@ -203,8 +203,8 @@ SPEC = %(
|
|
|
203
203
|
|
|
204
204
|
dump.value! -- VARIABLE...
|
|
205
205
|
Dumps values of the given variables. Multiple variables can be read into bash
|
|
206
|
-
variables using read:
|
|
207
|
-
|
|
206
|
+
variables using read:
|
|
207
|
+
|
|
208
208
|
read name title <<< $(prick dump value PRICK_NAME PRICK_TITLE)
|
|
209
209
|
|
|
210
210
|
dump.node!
|
|
@@ -217,7 +217,7 @@ SPEC = %(
|
|
|
217
217
|
TODO
|
|
218
218
|
)
|
|
219
219
|
|
|
220
|
-
def require_db(database = Prick.state&.database, exist: true)
|
|
220
|
+
def require_db(database = Prick.state&.database, exist: true)
|
|
221
221
|
database or raise ArgumentError
|
|
222
222
|
dba = State.connection
|
|
223
223
|
if exist
|
|
@@ -290,7 +290,7 @@ begin
|
|
|
290
290
|
state_file = opts.state_file || PRICK_STATE_PATH
|
|
291
291
|
|
|
292
292
|
# Process init command and exit
|
|
293
|
-
if opts.subcommand == :init!
|
|
293
|
+
if opts.subcommand == :init!
|
|
294
294
|
dir, name = Prick::SubCommand.init(project_file, args.expect(0..1), cmd.name, cmd.title)
|
|
295
295
|
Prick.mesg "Initialized Prick project '#{name}' in #{File.absolute_path(dir)}/"
|
|
296
296
|
exit
|
|
@@ -369,8 +369,8 @@ begin
|
|
|
369
369
|
arg = args.expect(1)
|
|
370
370
|
version = PrickVersion.try(arg) or Prick.error "Illegal version: #{arg}"
|
|
371
371
|
Prick::SubCommand.create_migration(
|
|
372
|
-
username, version,
|
|
373
|
-
force: create_command.subcommand!.force?,
|
|
372
|
+
username, version,
|
|
373
|
+
force: create_command.subcommand!.force?,
|
|
374
374
|
file: create_command.subcommand!.file)
|
|
375
375
|
when :users, :schema, :data, :all
|
|
376
376
|
raise NotImplementedError
|
|
@@ -384,7 +384,7 @@ begin
|
|
|
384
384
|
dump = cmd.dump? ? cmd.dump("batches")&.to_sym || :batches : nil
|
|
385
385
|
# exclude = cmd.exclude? ? cmd.exclude.split(",") : []
|
|
386
386
|
Prick::SubCommand.build(
|
|
387
|
-
database, username, args.expect(0..1),
|
|
387
|
+
database, username, args.expect(0..1),
|
|
388
388
|
force: cmd.force?, step: cmd.step?, timer: cmd.time?, dump: dump)
|
|
389
389
|
|
|
390
390
|
when :make!
|
|
@@ -392,7 +392,7 @@ begin
|
|
|
392
392
|
clean_pg_meta_cache
|
|
393
393
|
dump = cmd.dump? ? cmd.dump("batches")&.to_sym || :batches : nil
|
|
394
394
|
Prick::SubCommand.make(
|
|
395
|
-
database, username, args.expect(0..1),
|
|
395
|
+
database, username, args.expect(0..1),
|
|
396
396
|
step: cmd.step?, timer: cmd.time?, dump: dump)
|
|
397
397
|
|
|
398
398
|
when :run!
|
|
@@ -400,7 +400,7 @@ begin
|
|
|
400
400
|
clean_pg_meta_cache
|
|
401
401
|
dump = cmd.dump? ? cmd.dump("batches")&.to_sym || :batches : nil
|
|
402
402
|
Prick::SubCommand.run(
|
|
403
|
-
database, username, args.expect(1),
|
|
403
|
+
database, username, args.expect(1),
|
|
404
404
|
step: cmd.step?, timer: cmd.time?, dump: dump, schema: cmd.schema)
|
|
405
405
|
|
|
406
406
|
when :touch!
|
|
@@ -457,7 +457,7 @@ begin
|
|
|
457
457
|
|
|
458
458
|
when :release!
|
|
459
459
|
kind = args.expect(1).to_sym
|
|
460
|
-
constrain? kind, :major, :minor, :patch or
|
|
460
|
+
constrain? kind, :major, :minor, :patch or
|
|
461
461
|
Prick.failure "Expected 'major', 'minor', or 'patch' argument, got '#{kind}'"
|
|
462
462
|
Prick::SubCommand.release(kind)
|
|
463
463
|
|
|
@@ -472,7 +472,7 @@ begin
|
|
|
472
472
|
case cmd.subcommand
|
|
473
473
|
when :environments!; Prick::SubCommand.list_environments(format: format)
|
|
474
474
|
when :databases!; Prick::SubCommand.list_databases(format: format)
|
|
475
|
-
when :variables!;
|
|
475
|
+
when :variables!;
|
|
476
476
|
all = cmd.subcommand!.all?
|
|
477
477
|
Prick::SubCommand.list_variables(format: format, all: all)
|
|
478
478
|
when :users!; Prick::SubCommand.list_users
|
|
@@ -506,7 +506,7 @@ begin
|
|
|
506
506
|
raise NotImplementedError
|
|
507
507
|
when :variable!
|
|
508
508
|
scope =
|
|
509
|
-
case [subject.export?, subject.local?]
|
|
509
|
+
case [subject.export?, subject.local?]
|
|
510
510
|
in [true, false]; :global
|
|
511
511
|
in [false, true]; :local
|
|
512
512
|
in [false, false]; nil
|
|
@@ -544,7 +544,7 @@ rescue ShellOpts::Error, Prick::Error => ex
|
|
|
544
544
|
ShellOpts.error(ex.message)
|
|
545
545
|
|
|
546
546
|
# FIXME
|
|
547
|
-
#rescue RuntimeError, IOError, ShellOpts::Failure, Prick::Failure, Prick::Build::PostgresError => ex
|
|
547
|
+
#rescue RuntimeError, IOError, ShellOpts::Failure, Prick::Failure, Prick::Build::PostgresError => ex
|
|
548
548
|
# ShellOpts.failure(ex.message)
|
|
549
549
|
end
|
|
550
550
|
|
data/lib/prick/builder/batch.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Prick
|
|
|
11
11
|
|
|
12
12
|
def initialize(builder)
|
|
13
13
|
@builder = builder
|
|
14
|
-
@nodes = []
|
|
14
|
+
@nodes = []
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def execute(**opts, &block)
|
|
@@ -87,10 +87,10 @@ module Prick
|
|
|
87
87
|
|
|
88
88
|
class ModuleBatch < BuildBatch
|
|
89
89
|
def execute
|
|
90
|
-
super {
|
|
91
|
-
nodes.each { |node|
|
|
90
|
+
super {
|
|
91
|
+
nodes.each { |node|
|
|
92
92
|
sql = node&.call
|
|
93
|
-
conn.execute sql if sql
|
|
93
|
+
conn.execute sql if sql
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
end
|
|
@@ -140,7 +140,7 @@ module Prick
|
|
|
140
140
|
delete = builder.clean ? :none : :touched
|
|
141
141
|
begin
|
|
142
142
|
conn.execute fox.to_sql(format: :exec, delete: delete)
|
|
143
|
-
rescue PG::SyntaxError, PG::Error => ex
|
|
143
|
+
rescue PG::SyntaxError, PG::Error => ex
|
|
144
144
|
raise PostgresError.new(ex.message)
|
|
145
145
|
end
|
|
146
146
|
}
|
|
@@ -55,7 +55,7 @@ module Prick
|
|
|
55
55
|
:nodes, :decl_nodes, :init_nodes, :term_nodes,
|
|
56
56
|
:seed_nodes, :fox_seed_nodes, :sql_seed_nodes,
|
|
57
57
|
:build_nodes,
|
|
58
|
-
:pg_graph_ignore_schemas,
|
|
58
|
+
:pg_graph_ignore_schemas,
|
|
59
59
|
:refresh_schemas, :keep_schemas
|
|
60
60
|
|
|
61
61
|
def batches() @batches || create_batches end
|
|
@@ -160,7 +160,7 @@ module Prick
|
|
|
160
160
|
private
|
|
161
161
|
def load_pool_impl(build_node)
|
|
162
162
|
pool.add(build_node.init_nodes)
|
|
163
|
-
build_node.decl_nodes.each { |node|
|
|
163
|
+
build_node.decl_nodes.each { |node|
|
|
164
164
|
pool.add node
|
|
165
165
|
load_pool_impl(node) if node.kind == :yml
|
|
166
166
|
}
|
data/lib/prick/builder/node.rb
CHANGED
|
@@ -29,7 +29,7 @@ module Prick
|
|
|
29
29
|
|
|
30
30
|
def lines() prefix_lines + source_lines end
|
|
31
31
|
|
|
32
|
-
def initialize(parent, phase, kind, path, args = nil)
|
|
32
|
+
def initialize(parent, phase, kind, path, args = nil)
|
|
33
33
|
constrain parent, BuildNode, NilClass
|
|
34
34
|
constrain phase, :init, :decl, :seed, :term, nil
|
|
35
35
|
constrain kind, :sql, :exe, :fox, :yml, :inline, :module
|
|
@@ -60,7 +60,7 @@ module Prick
|
|
|
60
60
|
|
|
61
61
|
protected
|
|
62
62
|
def read_source
|
|
63
|
-
file = File.read(path)
|
|
63
|
+
file = File.read(path).gsub(/^\\[^\n]*/m, "")
|
|
64
64
|
@source_lines = 1 + 1 + file.count("\n")
|
|
65
65
|
["set search_path to #{schema}, pg_temp;\n", file]
|
|
66
66
|
end
|
|
@@ -110,7 +110,7 @@ module Prick
|
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
-
def call()
|
|
113
|
+
def call()
|
|
114
114
|
object.send(@command, *args)
|
|
115
115
|
end
|
|
116
116
|
|
|
@@ -200,7 +200,7 @@ module Prick
|
|
|
200
200
|
kind_nodes = self.send("#{kind}_nodes".to_sym)
|
|
201
201
|
if !kind_nodes.empty?
|
|
202
202
|
puts "#{kind}:"
|
|
203
|
-
indent { kind_nodes.each(&:dump) }
|
|
203
|
+
indent { kind_nodes.each(&:dump) }
|
|
204
204
|
end
|
|
205
205
|
end
|
|
206
206
|
}
|
|
@@ -35,7 +35,7 @@ module Prick
|
|
|
35
35
|
|
|
36
36
|
# List of schemas that should be rebuilt. #refresh_schemas is not cached
|
|
37
37
|
# and can be manipulated by removing build nodes from the pool
|
|
38
|
-
def refresh_schemas()
|
|
38
|
+
def refresh_schemas()
|
|
39
39
|
build_nodes.select(&:refresh_schema).map(&:schema).uniq
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -43,7 +43,7 @@ module Prick
|
|
|
43
43
|
build_nodes.reject(&:refresh_schema).map(&:schema).uniq
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def initialize()
|
|
46
|
+
def initialize()
|
|
47
47
|
self.clear
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -52,7 +52,7 @@ module Prick
|
|
|
52
52
|
term_nodes = [] # Ugly hack to do recursive init/term but preserve order within a term block
|
|
53
53
|
@nodes.concat(nodes)
|
|
54
54
|
@all_nodes.concat(nodes)
|
|
55
|
-
nodes.each { |node|
|
|
55
|
+
nodes.each { |node|
|
|
56
56
|
@schemas[node.schema] += 1
|
|
57
57
|
if node.phase == :term
|
|
58
58
|
term_nodes << node
|
|
@@ -60,7 +60,7 @@ module Prick
|
|
|
60
60
|
@kind_nodes[node.phase]&.append(node)
|
|
61
61
|
end
|
|
62
62
|
}
|
|
63
|
-
term_nodes.reverse.each { |node| @kind_nodes[:term]&.append node }
|
|
63
|
+
term_nodes.reverse.each { |node| @kind_nodes[:term]&.append node }
|
|
64
64
|
self
|
|
65
65
|
end
|
|
66
66
|
|
|
@@ -81,7 +81,7 @@ module Prick
|
|
|
81
81
|
|
|
82
82
|
def delete_schema(*schemas, exclude: [])
|
|
83
83
|
schemas = Array(schemas).flatten
|
|
84
|
-
delete_if { |node|
|
|
84
|
+
delete_if { |node|
|
|
85
85
|
schemas.include?(node.schema) && !exclude.include?(node.phase) && !exclude.include?(node.kind)
|
|
86
86
|
}
|
|
87
87
|
end
|
data/lib/prick/builder/parser.rb
CHANGED
|
@@ -105,7 +105,7 @@ module Prick
|
|
|
105
105
|
rest = $3
|
|
106
106
|
args = expand_string(rest || '').split
|
|
107
107
|
path = expand_filename(dir, command)
|
|
108
|
-
path || optional or
|
|
108
|
+
path || optional or
|
|
109
109
|
raise Error, "Can't find file #{command} #{path} in #{dir}/ from #{unit}"
|
|
110
110
|
!path.nil? or return nil
|
|
111
111
|
else
|
|
@@ -165,7 +165,7 @@ module Prick
|
|
|
165
165
|
|
|
166
166
|
# Search for an executable in path. Return nil if not found
|
|
167
167
|
#
|
|
168
|
-
# Note that "." is ignored in the search path
|
|
168
|
+
# Note that "." is ignored in the search path
|
|
169
169
|
def find_executable(filename) # ChatGPT
|
|
170
170
|
# puts "#find_executable(#{filename.inspect})"
|
|
171
171
|
if !Prick.state.environments.key?(filename) # Environment names are reserved
|
data/lib/prick/constants.rb
CHANGED
data/lib/prick/diff.rb
CHANGED
data/lib/prick/environment.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Prick
|
|
|
16
16
|
# List of names of inherited environments
|
|
17
17
|
def inherit = assignments[:inherit]
|
|
18
18
|
|
|
19
|
-
# List of directly inherited environment objects. Assigned by the
|
|
19
|
+
# List of directly inherited environment objects. Assigned by the
|
|
20
20
|
# analyzer
|
|
21
21
|
attr_accessor :parents
|
|
22
22
|
|
|
@@ -88,7 +88,7 @@ module Prick
|
|
|
88
88
|
def dump
|
|
89
89
|
puts "#{name}:"
|
|
90
90
|
indent {
|
|
91
|
-
self.each { |ident,val|
|
|
91
|
+
self.each { |ident,val|
|
|
92
92
|
# if ident == :build
|
|
93
93
|
# puts "super: #{super_environment&.name || 'false'}"
|
|
94
94
|
# end
|
|
@@ -163,11 +163,11 @@ module Prick
|
|
|
163
163
|
local method=$1
|
|
164
164
|
super_stack+=($method)
|
|
165
165
|
}
|
|
166
|
-
|
|
166
|
+
|
|
167
167
|
function pop_super_stack() {
|
|
168
168
|
super_stack=("${super_stack[@]::${#super_stack[@]}-1}")
|
|
169
169
|
}
|
|
170
|
-
|
|
170
|
+
|
|
171
171
|
function super() {
|
|
172
172
|
eval ${super_stack[-1]}
|
|
173
173
|
}
|
|
@@ -258,7 +258,7 @@ module Prick
|
|
|
258
258
|
def analyze
|
|
259
259
|
# Assign Environment#parent
|
|
260
260
|
values.each { |env|
|
|
261
|
-
env.parents = env.inherit.map { |name|
|
|
261
|
+
env.parents = env.inherit.map { |name|
|
|
262
262
|
self[name] or raise ArgumentError, "Can't find '#{name}' environment referred from '#{name}'"
|
|
263
263
|
}
|
|
264
264
|
}
|
|
@@ -279,10 +279,10 @@ module Prick
|
|
|
279
279
|
case type
|
|
280
280
|
when "BOOLEAN"; env[ident] = value if !env.key?(ident)
|
|
281
281
|
when "STRING"; env[ident] ||= value
|
|
282
|
-
when "LIST";
|
|
282
|
+
when "LIST";
|
|
283
283
|
next if ident == :inherit # Does not accumulate
|
|
284
284
|
# FIXME !inherited.key? should prevent env[ident].nil?
|
|
285
|
-
env[ident] = (value + (env[ident] || [])).uniq
|
|
285
|
+
env[ident] = (value + (env[ident] || [])).uniq
|
|
286
286
|
when "TEXT"; env[ident] = env[ident] || value
|
|
287
287
|
else
|
|
288
288
|
raise ArgumentError
|
|
@@ -294,7 +294,7 @@ module Prick
|
|
|
294
294
|
# Assign #ancestors
|
|
295
295
|
sorted_indexes = sorted_environments.map.with_index { |env, idx| [env.name, idx] }.to_h
|
|
296
296
|
for env in sorted_environments
|
|
297
|
-
env.ancestors =
|
|
297
|
+
env.ancestors =
|
|
298
298
|
(env.parents + env.parents.map(&:ancestors))
|
|
299
299
|
.flatten
|
|
300
300
|
.uniq
|
data/lib/prick/local/fmt.rb
CHANGED
|
@@ -7,7 +7,7 @@ module Fmt
|
|
|
7
7
|
types = []
|
|
8
8
|
indexes = [] # absolute position of column. Zero based
|
|
9
9
|
for i in (0...headers.size)
|
|
10
|
-
value_width =
|
|
10
|
+
value_width =
|
|
11
11
|
table.map { |row|
|
|
12
12
|
case value = row[i]
|
|
13
13
|
when TrueClass, FalseClass
|
|
@@ -75,7 +75,7 @@ module Fmt
|
|
|
75
75
|
lines = []
|
|
76
76
|
while !values.empty?
|
|
77
77
|
rest = width
|
|
78
|
-
line = []
|
|
78
|
+
line = []
|
|
79
79
|
while !values.empty? && values.first.size <= rest
|
|
80
80
|
rest -= values.first.size
|
|
81
81
|
line << values.shift
|
data/lib/prick/local/git.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
module Prick
|
|
3
3
|
module Git
|
|
4
4
|
# Return the origin of the repository
|
|
5
|
-
def self.origin()
|
|
5
|
+
def self.origin()
|
|
6
6
|
Command.command("git remote get-url origin").first
|
|
7
7
|
end
|
|
8
8
|
|
|
@@ -52,7 +52,7 @@ module Prick
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# Push change to repository
|
|
55
|
-
def self.push
|
|
55
|
+
def self.push
|
|
56
56
|
Command.command "git push --quiet --atomic"
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -67,34 +67,34 @@ module Prick
|
|
|
67
67
|
|
|
68
68
|
module Tag
|
|
69
69
|
# The associated commit ID of a tag
|
|
70
|
-
def self.id(tag)
|
|
71
|
-
tag && Command.command("git rev-list -n 1 #{tag}").first
|
|
70
|
+
def self.id(tag)
|
|
71
|
+
tag && Command.command("git rev-list -n 1 #{tag}").first
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
# True if tag exists
|
|
75
|
-
def self.exist?(tag)
|
|
76
|
-
tag && Command.command?("git describe --tags #{tag}")
|
|
75
|
+
def self.exist?(tag)
|
|
76
|
+
tag && Command.command?("git describe --tags #{tag}")
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
# Create tag
|
|
80
|
-
def self.create(tag, id: nil)
|
|
81
|
-
Command.command "git tag '#{tag}' #{id}"
|
|
80
|
+
def self.create(tag, id: nil)
|
|
81
|
+
Command.command "git tag '#{tag}' #{id}"
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
# Drop a tag
|
|
85
|
-
def self.drop(tag)
|
|
86
|
-
Command.command "git tag -d '#{tag}'"
|
|
85
|
+
def self.drop(tag)
|
|
86
|
+
Command.command "git tag -d '#{tag}'"
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
# Return list of all tags. Not in any particular order
|
|
90
|
-
def self.list()
|
|
91
|
-
Command.command("git tag")
|
|
90
|
+
def self.list()
|
|
91
|
+
Command.command("git tag")
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
# Return the most recent tag before the given commit (defaults to the
|
|
95
95
|
# last commit)
|
|
96
|
-
def self.current(id = nil)
|
|
97
|
-
describe_tag(id)&.first
|
|
96
|
+
def self.current(id = nil)
|
|
97
|
+
describe_tag(id)&.first
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
private
|
|
@@ -115,11 +115,11 @@ module Prick
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
module Branch
|
|
118
|
-
def self.exist?(branch)
|
|
118
|
+
def self.exist?(branch)
|
|
119
119
|
Command.command? "git show-ref --verify --quiet refs/heads/#{branch}"
|
|
120
120
|
end
|
|
121
121
|
|
|
122
|
-
def self.create(branch, id = nil, set_upstream: true)
|
|
122
|
+
def self.create(branch, id = nil, set_upstream: true)
|
|
123
123
|
if set_upstream
|
|
124
124
|
current = Git.branch.current
|
|
125
125
|
Command.command %(
|
|
@@ -132,7 +132,7 @@ module Prick
|
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
def self.drop(branch)
|
|
135
|
+
def self.drop(branch)
|
|
136
136
|
Command.command "git branch -D #{branch}"
|
|
137
137
|
end
|
|
138
138
|
|
|
@@ -140,11 +140,11 @@ module Prick
|
|
|
140
140
|
Command.command "git for-each-ref --format='%(refname:short)' refs/heads/*"
|
|
141
141
|
end
|
|
142
142
|
|
|
143
|
-
def self.current()
|
|
143
|
+
def self.current()
|
|
144
144
|
Command.command("git branch --show-current").first
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
-
def self.checkout(branch)
|
|
147
|
+
def self.checkout(branch)
|
|
148
148
|
Command.command "git checkout --quiet #{branch}"
|
|
149
149
|
end
|
|
150
150
|
end
|
|
@@ -158,7 +158,7 @@ __END__
|
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
# Return true if `version` has an associated tag
|
|
163
163
|
def self.tag?(version)
|
|
164
164
|
!list_tags.grep(version.to_s).empty?
|
data/lib/prick/local/timer.rb
CHANGED
|
@@ -62,15 +62,15 @@ module Timer
|
|
|
62
62
|
|
|
63
63
|
def to_s(title = self.title) "#{title}: #{Timer.format(time)}" end
|
|
64
64
|
|
|
65
|
-
def emit(title = self.title)
|
|
65
|
+
def emit(title = self.title)
|
|
66
66
|
stop
|
|
67
67
|
::Timer.file.puts to_s(title) if ::Timer.on?
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def self.factor() { s: 1, ms: 1000 }[::Timer.unit] end
|
|
71
71
|
|
|
72
|
-
def self.format(time)
|
|
73
|
-
time ? sprintf("%.#{::Timer.scale}f#{::Timer.unit}", Timer.factor * time) : time.inspect
|
|
72
|
+
def self.format(time)
|
|
73
|
+
time ? sprintf("%.#{::Timer.scale}f#{::Timer.unit}", Timer.factor * time) : time.inspect
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
|
data/lib/prick/prick_version.rb
CHANGED
|
@@ -15,9 +15,9 @@ module Prick
|
|
|
15
15
|
def zero?() self == PrickVersion.zero end
|
|
16
16
|
|
|
17
17
|
# Return true if `string` is a version
|
|
18
|
-
def self.version?(string)
|
|
18
|
+
def self.version?(string)
|
|
19
19
|
string.is_a?(String) or raise Internal, "String expected"
|
|
20
|
-
!(string =~ VERSION_RE).nil?
|
|
20
|
+
!(string =~ VERSION_RE).nil?
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
attr_accessor :fork
|
|
@@ -95,9 +95,9 @@ module Prick
|
|
|
95
95
|
[version, tag]
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
-
# `part` can be one of :major, :minor, :patch, or :pre. If pre is undefined, it
|
|
98
|
+
# `part` can be one of :major, :minor, :patch, or :pre. If pre is undefined, it
|
|
99
99
|
# is set to `pre_initial_value`
|
|
100
|
-
def increment(part, pre_initial_value = 1)
|
|
100
|
+
def increment(part, pre_initial_value = 1)
|
|
101
101
|
self.dup.increment!(part, pre_initial_value)
|
|
102
102
|
end
|
|
103
103
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Note the SQL scripts are also called directly from 'prick setup' when the
|
|
4
4
|
# database is created because we don't want to parse the whole build
|
|
5
5
|
# environment just to create the prick schema. After the initial setup, the
|
|
6
|
-
# scripts are only run by 'prick build' with the --force option
|
|
6
|
+
# scripts are only run by 'prick build' with the --force option
|
|
7
7
|
#
|
|
8
8
|
# This is hardcoded an should be fixed somehow
|
|
9
9
|
#
|
data/lib/prick/state.rb
CHANGED
|
@@ -45,7 +45,7 @@ module Prick
|
|
|
45
45
|
attr_accessor :version
|
|
46
46
|
|
|
47
47
|
# Version of prick in prick.yml. Note that this can be different than the current
|
|
48
|
-
# version of prick
|
|
48
|
+
# version of prick
|
|
49
49
|
attr_accessor :prick_version
|
|
50
50
|
|
|
51
51
|
# Database name. nil if state file is absent
|
|
@@ -82,7 +82,7 @@ module Prick
|
|
|
82
82
|
def branch() @branch ||= Git.branch.current end
|
|
83
83
|
|
|
84
84
|
# Git revision (commit ID). Lazy-evaluated
|
|
85
|
-
def rev(kind: :long)
|
|
85
|
+
def rev(kind: :long)
|
|
86
86
|
case kind
|
|
87
87
|
when :short; @rev_short ||= rev()[0...8]
|
|
88
88
|
when :long; @rev_long ||= Git.id
|
|
@@ -90,7 +90,7 @@ module Prick
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
# True if the git repository is clean (not modified). Lazy-evaluated
|
|
93
|
-
def clean?()
|
|
93
|
+
def clean?()
|
|
94
94
|
return @clean if defined?(@clean)
|
|
95
95
|
@clean = Git.clean?
|
|
96
96
|
end
|
|
@@ -109,7 +109,7 @@ module Prick
|
|
|
109
109
|
load_environment_file if @environment_file && File.exist?(@environment_file)
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
-
# Project user (owner) connection. Memoized to connect only once.
|
|
112
|
+
# Project user (owner) connection. Memoized to connect only once.
|
|
113
113
|
# TODO Rename. Also rename self.connection
|
|
114
114
|
def connection(database: nil, username: nil, environment: nil, &block)
|
|
115
115
|
if @connection.nil?
|
|
@@ -125,9 +125,9 @@ module Prick
|
|
|
125
125
|
load_database_environment
|
|
126
126
|
|
|
127
127
|
# Set environment if undefined and not overridden by :environment
|
|
128
|
-
self.environment =
|
|
129
|
-
environment ||
|
|
130
|
-
Prick.state.environment ||
|
|
128
|
+
self.environment =
|
|
129
|
+
environment ||
|
|
130
|
+
Prick.state.environment ||
|
|
131
131
|
environments.key?(database_environment) && database_environment ||
|
|
132
132
|
DEFAULT_ENVIRONMENT
|
|
133
133
|
end
|
|
@@ -160,8 +160,8 @@ module Prick
|
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
# Create a bash(1) environment (Hash). It is used for in-prick expansion of
|
|
163
|
-
# variables and is also injected into the enviroment of subprocesses
|
|
164
|
-
#
|
|
163
|
+
# variables and is also injected into the enviroment of subprocesses
|
|
164
|
+
#
|
|
165
165
|
# FIXME: Problems with BUNDLE_* variables FIXME Still a problem?
|
|
166
166
|
#
|
|
167
167
|
# TODO: Explain handling of PRICK_<STANDARD-DIRECTORY>
|
|
@@ -231,12 +231,12 @@ module Prick
|
|
|
231
231
|
val = val.join(" ")
|
|
232
232
|
end
|
|
233
233
|
end
|
|
234
|
-
assignments << "#{prefix}#{var}='#{val}'\n"
|
|
234
|
+
assignments << "#{prefix}#{var}='#{val}'\n"
|
|
235
235
|
}
|
|
236
236
|
assignments.join
|
|
237
237
|
end
|
|
238
238
|
|
|
239
|
-
# It is an error if the project file exists.
|
|
239
|
+
# It is an error if the project file exists.
|
|
240
240
|
def save_project(overwrite: false)
|
|
241
241
|
overwrite || !File.exists?(project_file) or Prick.error "Won't overwrite '#{project_file}'"
|
|
242
242
|
hash = { name: name, title: title, version: version.to_s, prick: Prick::VERSION }
|
|
@@ -268,7 +268,7 @@ module Prick
|
|
|
268
268
|
branch: branch, rev: rev(kind: :short), clean: clean?,
|
|
269
269
|
environment: environment)
|
|
270
270
|
end
|
|
271
|
-
# version: version.to_s, prick: prick_version,
|
|
271
|
+
# version: version.to_s, prick: prick_version,
|
|
272
272
|
end
|
|
273
273
|
|
|
274
274
|
def save_build_end(success, duration)
|
|
@@ -279,7 +279,7 @@ module Prick
|
|
|
279
279
|
insert_record(
|
|
280
280
|
"prick.builds",
|
|
281
281
|
name: name,
|
|
282
|
-
version: version.to_s, prick: Prick::VERSION,
|
|
282
|
+
version: version.to_s, prick: Prick::VERSION,
|
|
283
283
|
branch: branch, rev: rev(kind: :short), clean: clean?,
|
|
284
284
|
environment: environment,
|
|
285
285
|
success: success, duration: duration, prick_duration: dt)
|
|
@@ -300,7 +300,7 @@ module Prick
|
|
|
300
300
|
puts "State"
|
|
301
301
|
indent {
|
|
302
302
|
for method in [
|
|
303
|
-
:name, :title, :prick_version, :project_version,
|
|
303
|
+
:name, :title, :prick_version, :project_version,
|
|
304
304
|
:database_version, :database_environment, :database, :username]
|
|
305
305
|
puts "#{method}: #{self.send method}"
|
|
306
306
|
end
|
|
@@ -327,7 +327,7 @@ module Prick
|
|
|
327
327
|
for key in mandatory_keys
|
|
328
328
|
!hash[key].to_s.empty? or Prick.error "Can't find '#{key}' in #{file}"
|
|
329
329
|
end
|
|
330
|
-
(unknown = (hash.keys - mandatory_keys - optional_keys).first) and
|
|
330
|
+
(unknown = (hash.keys - mandatory_keys - optional_keys).first) and
|
|
331
331
|
Prick.error "Illegal key '#{unknown}' in #{file}"
|
|
332
332
|
hash
|
|
333
333
|
end
|
|
@@ -4,8 +4,8 @@ require_relative '../builder/builder.rb'
|
|
|
4
4
|
|
|
5
5
|
module Prick::SubCommand
|
|
6
6
|
def self.build(
|
|
7
|
-
database, username, schema,
|
|
8
|
-
builddir: Prick.state.schema_dir,
|
|
7
|
+
database, username, schema,
|
|
8
|
+
builddir: Prick.state.schema_dir,
|
|
9
9
|
force: false, # Build all schemas
|
|
10
10
|
step: false, timer: nil, dump: nil)
|
|
11
11
|
|
|
@@ -43,7 +43,7 @@ module Prick::SubCommand
|
|
|
43
43
|
refresh_schemas = conn.schema.list
|
|
44
44
|
|
|
45
45
|
# Find existing keep-schemas (but exclude target schema)
|
|
46
|
-
keep_schemas = builder.keep_schemas.select { |s|
|
|
46
|
+
keep_schemas = builder.keep_schemas.select { |s|
|
|
47
47
|
conn.schema.exist?(s) && (schema.nil? || schema != s)
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -63,7 +63,7 @@ module Prick::SubCommand
|
|
|
63
63
|
# 'prick build' was given a schema
|
|
64
64
|
builder.pool.delete_schema(builder.pool.after_schema(schema)) if schema
|
|
65
65
|
end
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
case dump
|
|
68
68
|
when :nodes; builder.nodes.reject { |node| node.is_a?(Build::BuildNode) }.map &:dump
|
|
69
69
|
when :allnodes; builder.nodes.map &:dump
|
|
@@ -35,7 +35,7 @@ module Prick
|
|
|
35
35
|
built_at: nil,
|
|
36
36
|
success: nil
|
|
37
37
|
end
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
def self.create_migration(username, from_version, force: false, file: nil)
|
|
40
40
|
constrain from_version, PrickVersion
|
|
41
41
|
Git.clean? or raise "Won't migrate: Repository is dirty"
|
|
@@ -97,7 +97,7 @@ module Prick
|
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
if file
|
|
100
|
-
File.open(file, "a") { |f|
|
|
100
|
+
File.open(file, "a") { |f|
|
|
101
101
|
f.puts "-- UPDATE VERSION"
|
|
102
102
|
f.puts File.readlines(SCHEMA_VERSION_PATH).grep_v(/^--/)
|
|
103
103
|
}
|
|
@@ -106,7 +106,7 @@ module Prick
|
|
|
106
106
|
FileUtils.mkdir_p migration_dir
|
|
107
107
|
Command.command "cp -a #{SHARE_PATH}/migrate/migration/. #{migration_dir}"
|
|
108
108
|
Dir.chdir(migration_dir) { diff.write(*DIFF_FILES, mark: true) }
|
|
109
|
-
end
|
|
109
|
+
end
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
end
|
|
@@ -4,7 +4,7 @@ require_relative '../builder/builder.rb'
|
|
|
4
4
|
|
|
5
5
|
module Prick::SubCommand
|
|
6
6
|
# Drop database owner
|
|
7
|
-
def self.drop_owner(username)
|
|
7
|
+
def self.drop_owner(username)
|
|
8
8
|
# No database at this point so no session is running and no cascade. A nop
|
|
9
9
|
# if the user is the current user or owns objects in other databases
|
|
10
10
|
if username != ENV['USER']
|
|
@@ -21,7 +21,7 @@ module Prick::SubCommand
|
|
|
21
21
|
if conn.rdbms.exist? database
|
|
22
22
|
users = conn.role.list(database: database).reject { _1 == conn.rdbms.owner(database) }
|
|
23
23
|
conn.session.terminate(database, users)
|
|
24
|
-
if conn.rdbms.exist?(database)
|
|
24
|
+
if conn.rdbms.exist?(database)
|
|
25
25
|
# Connect to database to make cascade work. Run in a block to close connection afterwards
|
|
26
26
|
PgConn.new(database) { |conn| conn.role.drop(users, cascade: true) }
|
|
27
27
|
else
|
|
@@ -53,7 +53,7 @@ module Prick::SubCommand
|
|
|
53
53
|
schema_list = conn.quote_literal_list(schemas)
|
|
54
54
|
schema_expr = schemas ? "true = true" : "schema_name in #{schema_list}"
|
|
55
55
|
tables = conn.tuples %(
|
|
56
|
-
select schema_name, table_name, max_id
|
|
56
|
+
select schema_name, table_name, max_id
|
|
57
57
|
from prick.snapshots
|
|
58
58
|
where #{schema_expr}
|
|
59
59
|
)
|
|
@@ -30,7 +30,7 @@ __END__
|
|
|
30
30
|
builder = Prick::Build::Builder.new(conn, builddir)
|
|
31
31
|
builder.pool.delete_schema(builder.pool.after_schema(schema)) if schema
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
case dump
|
|
35
35
|
when :nodes; builder.nodes.reject { |node| node.is_a?(Build::BuildNode) }.map &:dump
|
|
36
36
|
when :allnodes; builder.nodes.map &:dump
|
|
@@ -17,7 +17,7 @@ module Prick::SubCommand
|
|
|
17
17
|
headers = %w(variable value)
|
|
18
18
|
vars = Prick.state.bash_environment(all: all).reject { |k,v| k == "PATH" }
|
|
19
19
|
rows = vars.map
|
|
20
|
-
# rows = vars.map { |k,v|
|
|
20
|
+
# rows = vars.map { |k,v|
|
|
21
21
|
# if v.is_a?(Array)
|
|
22
22
|
# if v.first&.is_a?(Array)
|
|
23
23
|
# v = v.first
|
|
@@ -28,7 +28,7 @@ module Prick::SubCommand
|
|
|
28
28
|
# v = v.to_s
|
|
29
29
|
# end
|
|
30
30
|
#
|
|
31
|
-
# [k, v]
|
|
31
|
+
# [k, v]
|
|
32
32
|
# }
|
|
33
33
|
Fmt.puts_table(headers, rows)
|
|
34
34
|
end
|
|
@@ -52,8 +52,8 @@ module Prick::SubCommand
|
|
|
52
52
|
rows = []
|
|
53
53
|
Prick.databases { |database, conn|
|
|
54
54
|
row = conn.record(%(
|
|
55
|
-
select
|
|
56
|
-
'#{database}' as "database", name, version, branch, rev, clean, environment,
|
|
55
|
+
select
|
|
56
|
+
'#{database}' as "database", name, version, branch, rev, clean, environment,
|
|
57
57
|
built_at, success
|
|
58
58
|
from prick.versions
|
|
59
59
|
))
|
|
@@ -64,12 +64,12 @@ module Prick::SubCommand
|
|
|
64
64
|
up2date = fs_time <= row[:built_at]
|
|
65
65
|
|
|
66
66
|
# Set state
|
|
67
|
-
row[:state] =
|
|
67
|
+
row[:state] =
|
|
68
68
|
case [clean, same_revision, up2date]
|
|
69
69
|
in [true, true, true]; "clean" # Built from clean repo
|
|
70
70
|
in [true, true, false]; "ok" # Clean repo but doesn't include latest uncommitted changes
|
|
71
71
|
in [true, false, _]; "clean" # Clean repo but different revision
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
in [false, true, true]; "edge" # Dirty repo, work-in-progress
|
|
74
74
|
in [false, true, false]; "dirty" # Dirty repo and doesn't include latest changes
|
|
75
75
|
in [false, false, _]; "stale" # Dirty repo, no way back
|
|
@@ -100,7 +100,7 @@ module Prick::SubCommand
|
|
|
100
100
|
def self.list_owners(format: :long)
|
|
101
101
|
owners = {}
|
|
102
102
|
Prick.databases.each { |database|
|
|
103
|
-
# owner = super_conn.rdbms.exist?(d) ? super_conn.rdbms.owner(d) : d
|
|
103
|
+
# owner = super_conn.rdbms.exist?(d) ? super_conn.rdbms.owner(d) : d
|
|
104
104
|
owner = super_conn.rdbms.owner(database)
|
|
105
105
|
(owners[owner] ||= []) << database
|
|
106
106
|
}
|
|
@@ -108,9 +108,9 @@ module Prick::SubCommand
|
|
|
108
108
|
puts owners.keys
|
|
109
109
|
else
|
|
110
110
|
headers = %w(username databases) + [" "]
|
|
111
|
-
rows = owners.map { |owner, databases|
|
|
111
|
+
rows = owners.map { |owner, databases|
|
|
112
112
|
current_user_mark = (Prick.state.username == owner ? '*' : "")
|
|
113
|
-
[owner, databases.join(","), current_user_mark]
|
|
113
|
+
[owner, databases.join(","), current_user_mark]
|
|
114
114
|
}
|
|
115
115
|
Fmt.puts_table(headers, rows)
|
|
116
116
|
end
|
|
@@ -28,12 +28,12 @@ module Prick::SubCommand
|
|
|
28
28
|
|
|
29
29
|
builder = Prick::Build::Builder.new(conn, "schema", clean, step: step)
|
|
30
30
|
|
|
31
|
-
if schema
|
|
31
|
+
if schema
|
|
32
32
|
after_schemas = builder.pool.after_schema(schema)
|
|
33
33
|
refresh_schemas = builder.pool.refresh_schemas
|
|
34
34
|
conn.schema.drop(schema, cascade: true) # Marks it dirty
|
|
35
35
|
|
|
36
|
-
# Nuke later schemas
|
|
36
|
+
# Nuke later schemas
|
|
37
37
|
# FIXME Not a good idea when sitting on a leaf schema.
|
|
38
38
|
# Forced-delete could be requested using 'prick make schema'
|
|
39
39
|
#
|
|
@@ -49,7 +49,7 @@ module Prick::SubCommand
|
|
|
49
49
|
touched_schema = touched_nodes.first&.schema
|
|
50
50
|
missing_schema = builder.schemas.find { |schema| !conn.schema.exist?(schema) }
|
|
51
51
|
build_schema = builder.schemas.find { |schema| [touched_schema, missing_schema].include? schema }
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
if build_schema.nil?
|
|
54
54
|
puts "#{database} is up to date"
|
|
55
55
|
exit
|
|
@@ -39,7 +39,7 @@ module Prick::SubCommand
|
|
|
39
39
|
else
|
|
40
40
|
is_build_file = false
|
|
41
41
|
end
|
|
42
|
-
|
|
42
|
+
|
|
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
|
|
@@ -70,7 +70,7 @@ module Prick::SubCommand
|
|
|
70
70
|
|
|
71
71
|
# Drop schema if needed
|
|
72
72
|
if is_schema_rebuild
|
|
73
|
-
conn.schema.drop schema, cascade: true
|
|
73
|
+
conn.schema.drop schema, cascade: true
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
# Create schema if absent
|
data/lib/prick/version.rb
CHANGED
data/lib/prick.rb
CHANGED
|
@@ -77,13 +77,13 @@ module Prick
|
|
|
77
77
|
databases = super_conn.values %(
|
|
78
78
|
select datname from pg_database where datistemplate = false order by datname
|
|
79
79
|
)
|
|
80
|
-
databases.select! { |database|
|
|
80
|
+
databases.select! { |database|
|
|
81
81
|
PgConn.new(database) { |conn|
|
|
82
82
|
is_prick_database = conn.exist?(%(
|
|
83
|
-
select 1
|
|
84
|
-
from information_schema.tables
|
|
83
|
+
select 1
|
|
84
|
+
from information_schema.tables
|
|
85
85
|
where table_schema = 'prick'
|
|
86
|
-
and table_name = 'builds'
|
|
86
|
+
and table_name = 'builds'
|
|
87
87
|
limit 1
|
|
88
88
|
))
|
|
89
89
|
yield(database, conn) if is_prick_database && block_given?
|
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.39.
|
|
4
|
+
version: 0.39.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Claus Rasmussen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-07-
|
|
11
|
+
date: 2024-07-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: semantic
|