prick 0.42.1 → 0.43.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7ebbfeaeaecdac6bd79e104061ffe80701a06625f28b7c6fcace327f49802ec
4
- data.tar.gz: 2d117c660b47c1812ef1316777f923603abfc09a230270ee25655f3a7c41b99d
3
+ metadata.gz: 776071ac8d6762ee4a9d60f40c308a13be0fc51451ad52844e5821b3ec72d330
4
+ data.tar.gz: c2d0d5637d8948853574edb40a932ec632f4dd6c53ce19b8fd18c64b6e639ab0
5
5
  SHA512:
6
- metadata.gz: 3407f818ce8b7e927eb8becf3522cdef8994c997e0bc835b079515b78bbad5b5523a9262bbd0f48e85ee1b81cc15094519bea5b24de0b2fe74c617a186563e97
7
- data.tar.gz: 9d4c4dbdcc3569322926c7b2a79240b31f4eb8825da838547308a88400d1cf36f0e17866b154b7dbc4098a6bcc7b4dd1509fd37cfaefd8e69f8cc8c96a5ae564
6
+ metadata.gz: cbfb74c1775869db3ec1b2d24a8d69565d9b785220c9ec9c4051bb6f63de23709c71df4c4109d5de889352e66710fedcb1ca2ba667dfdd79f31f66396de35188
7
+ data.tar.gz: 6a9e7b64410e37e7449e5c09ef41cdac244d3050418ea04b2ca6aa5316d716d415caba1be6a4ab280875eb345eddd99f9e7e4f527a7ebfc1673b439cf457a3a5
@@ -50,9 +50,7 @@ module Prick
50
50
  end
51
51
 
52
52
  begin
53
- for node in nodes # This is marginally faster than concatenating all nodes
54
- conn.execute node.source, silent: true
55
- end
53
+ execute_nodes
56
54
  rescue PG::Error => ex
57
55
  error, line, char = conn.err
58
56
  file = nil
@@ -81,13 +79,29 @@ module Prick
81
79
  elsif node
82
80
  message = "#{error} from #{node.path}"
83
81
  else
84
- raise ArgumentError, "Oops"
85
- message = conn.errmsg + " in SQL batch"
82
+ message = "Error in #{nodes.first.path}: #{conn.errmsg}"
86
83
  end
87
84
  raise PostgresError.new(message, file, line, char)
88
85
  end
89
86
  }
90
87
  end
88
+
89
+ protected
90
+ def execute_nodes
91
+ for node in nodes # This is marginally faster than concatenating all nodes
92
+ conn.execute node.source, silent: true
93
+ end
94
+ end
95
+ end
96
+
97
+ class PSqlBatch < SqlBatch
98
+ protected
99
+ def execute_nodes
100
+ opts = ["-U #{Prick.state.username}"] + nodes.map { |n| "-f #{n.path}" }
101
+ args = [Prick.state.database]
102
+
103
+ Command.command(Prick.state.bash_environment, "psql", argv: opts + args)
104
+ end
91
105
  end
92
106
 
93
107
  class ModuleBatch < BuildBatch
@@ -87,6 +87,7 @@ module Prick
87
87
  kind = nil
88
88
  batch = nil
89
89
 
90
+ # TODO: Refactor
90
91
  for node in [init_nodes, decl_nodes, fox_seed_nodes, sql_seed_nodes, term_nodes.reverse].flatten
91
92
  # Create new batch if required. Order of when-clauses is important
92
93
  case node.kind
@@ -98,16 +99,23 @@ module Prick
98
99
  when :exe # Exe sources always create a new batch
99
100
  @batches << batch if batch
100
101
  batch = SqlBatch.new(self)
101
- when batch&.kind # Same kind as current batch
102
+ when batch&.kind # Same kind as current batch. After this when-clause
103
+ # we know that the node kind has changed
102
104
  if node.kind == :sql && step
103
105
  @batches << batch if batch
104
106
  batch = SqlBatch.new(self)
107
+ elsif node.kind == :psql && step
108
+ @batches << batch if batch
109
+ batch = SqlBatch.new(self)
105
110
  end
106
111
  when :sql || node.kind == :inline
107
112
  if batch&.kind != :exe || step
108
113
  @batches << batch if batch
109
114
  batch = SqlBatch.new(self)
110
115
  end
116
+ when :psql
117
+ @batches << batch if batch
118
+ batch = PSqlBatch.new(self)
111
119
  when :inline
112
120
  @batches << batch if batch
113
121
  batch = SqlBatch.new(self)
@@ -123,6 +131,8 @@ module Prick
123
131
  # Add node to current batch
124
132
  batch.nodes << node
125
133
  end
134
+
135
+ # Add last batch
126
136
  @batches << batch if batch
127
137
 
128
138
  @batches
@@ -33,7 +33,7 @@ module Prick
33
33
  def initialize(parent, phase, kind, path, args = nil)
34
34
  constrain parent, BuildNode, NilClass
35
35
  constrain phase, :init, :decl, :seed, :term, nil
36
- constrain kind, :sql, :exe, :fox, :yml, :inline, :module
36
+ constrain kind, :sql, :psql, :exe, :fox, :yml, :inline, :module
37
37
  constrain path, String, NilClass
38
38
  @parent, @phase, @kind, @path = parent, phase, kind, path
39
39
  @args = args&.empty? ? nil : args
@@ -67,6 +67,12 @@ module Prick
67
67
  end
68
68
  end
69
69
 
70
+ class PSqlNode < Node
71
+ def initialize(parent, phase, path)
72
+ super(parent, phase, :psql, path)
73
+ end
74
+ end
75
+
70
76
  class FoxNode < Node
71
77
  def initialize(parent, phase, path)
72
78
  super(parent, phase, :fox, path)
@@ -115,6 +115,16 @@ module Prick
115
115
  [path, Array(args).flatten]
116
116
  end
117
117
 
118
+ def parse_psql_file_entry(unit, dir, entry)
119
+ if entry =~ /^[a-zA-Z0-9_.-]+$/
120
+ path = File.join(dir, entry)
121
+ File.exist?(path) or raise Error, "Can't find file #{path} in #{dir}/ from #{unit}"
122
+ path
123
+ else
124
+ raise Error, "Not a file name: '#{entry}'"
125
+ end
126
+ end
127
+
118
128
  def parse_entry(unit, phase, dir, entry)
119
129
  # puts "#parse_entry(#{unit.inspect}, #{phase.inspect}, #{dir.inspect}, #{entry.inspect})"
120
130
  if entry.is_a?(Hash)
@@ -145,6 +155,9 @@ module Prick
145
155
  else
146
156
  raise Error, "Illegal key: #{key}"
147
157
  end
158
+ elsif entry =~ /\.psql$/
159
+ path = parse_psql_file_entry(unit, dir, entry)
160
+ PSqlNode.new(unit, phase, path)
148
161
  else
149
162
  (path, args = parse_file_entry(unit, dir, entry)) or return nil
150
163
  if File.directory? path
@@ -187,7 +200,7 @@ module Prick
187
200
 
188
201
  # Expand environment variables in the given file name
189
202
  #
190
- # #expend_filename substitute '$<variable>' expressions in the filename
203
+ # #expand_filename substitute '$<variable>' expressions in the filename
191
204
  # with the corresponding value in the current environment. If the file
192
205
  # was not found, inherited environments are processed hierarchly with the
193
206
  # special environment variable ENVIRONMENT set to each PRICK_ENVIRONMENT
@@ -14,7 +14,7 @@
14
14
  def expand_variables(str, variables) # ChatGPT
15
15
  # Replace escaped bashslashes and dollar signs
16
16
  str = str.gsub('\\\\', "\x00").gsub('\\$', "\x01")
17
-
17
+
18
18
  # Expand variables
19
19
  str.gsub!(/\$(\w+)\b|\$\{(\w+)\}/) do |match| # Strange that '\b' is necessary
20
20
  key = $1 || $2
@@ -30,7 +30,7 @@ end
30
30
  def expand_variables?(str, variables)
31
31
  # Replace escaped bashslashes and dollar signs
32
32
  str = str.gsub('\\\\', "\x00").gsub('\\$', "\x01")
33
-
33
+
34
34
  # Look for expansion
35
35
  str.gsub!(/\$(\w+)\b|\$\{(\w+)\}/) do |match| # Strange that '\b' is necessary
36
36
  return true if variables.include?($1 || $2)
@@ -38,3 +38,10 @@ def expand_variables?(str, variables)
38
38
 
39
39
  return false
40
40
  end
41
+
42
+ # Return true if the string contains a variable
43
+ def has_variables?(str)
44
+ # Replace escaped bashslashes and dollar signs
45
+ str = str.gsub('\\\\', "\x00").gsub('\\$', "\x01")
46
+ !(str =~ /\$[a-zA-Z{]/).nil?
47
+ end
@@ -43,7 +43,7 @@ module Prick::SubCommand
43
43
  puts Prick.databases
44
44
  else
45
45
  # Timestamp of newest file under git control
46
- newest_file = Command.command("ls -tr #{Git.list.join(" ")} | tail -1").last
46
+ newest_file = Command.command("ls -tr #{Git.list.join(" ")} | tail -1", stderr: false, fail: false).last
47
47
  fs_time = File.mtime(newest_file)
48
48
 
49
49
  git_branch = Git.branch.current
@@ -59,7 +59,7 @@ module Prick::SubCommand
59
59
  from prick.versions
60
60
  ))
61
61
 
62
- # Detect is this is the current database
62
+ # Detect if this is the current database
63
63
  if Prick.state.database == database
64
64
  is_current_database = true
65
65
  current_database_row = rows.size
data/lib/prick/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prick
4
- VERSION = "0.42.1"
4
+ VERSION = "0.43.0"
5
5
  end
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.42.1
4
+ version: 0.43.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: 2024-10-15 00:00:00.000000000 Z
11
+ date: 2024-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic