prick 0.20.12 → 0.20.15

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: 9bbd123a6ed9f156d8e3408f12a1abbcccac79b135eb23534729545cce186978
4
- data.tar.gz: cc694d4fce96f0e89e481ea6ae8d0af9c3ee81549acfd87695fc49e05b907d42
3
+ metadata.gz: 364c4c7c99807892c0714d99d531d19fe7fff8cfe23f80e56679d8649630b416
4
+ data.tar.gz: 5e2fcd8e46a130dd65451a76c22027352bd5b5a747d3996940f5f1c4941c1953
5
5
  SHA512:
6
- metadata.gz: a89feccaa6e1c4773c15247e36650b65fb8db37d4f76eac6dc557844a346429b516c93d0b98658362ba85a733205cd7ddce75d3c105523018abaad7cfff1f15d
7
- data.tar.gz: 9467de6887a0d8161c71e046fe5c802149719e3a1db8a7f6ddbd31a1687eb166fe179ebe6ddf634f28efb86b6720716ed5074953c36bbf3eee59b940a4db280e
6
+ metadata.gz: 7e185c8ffc7d29d764672647994c95f67dcb8deb8ff2ab0fbe9edc278b8934b448834327b46897f0a92b268cb94b82011369c25035cba911358739f93ab6ed95
7
+ data.tar.gz: 18c403ced7bad45431dc4c63c3d00a4d9f9425f5096e8f1c736be81d99f3f814e0a7ecff9a6e72f6cd794703219e76b026e9c2bc9b132570f65ae470dbb75e95
data/exe/prick CHANGED
@@ -74,10 +74,13 @@ SPEC = %(
74
74
  Kind can be 'users', 'data', 'schema', 'database' (the default), or 'all'. It is
75
75
  not an error if the object doesn't exist. TODO Only 'users' is currently defined
76
76
 
77
- build! -t,time --dump=KIND? -- [SCHEMA]
77
+ build! -f,force -t,time --dump=KIND? -- [SCHEMA]
78
78
  Build the project. If SCHEMA is defined, later schemas are excluded.
79
79
  KIND can be 'nodes', 'allnodes' or 'batches' (the default)
80
80
 
81
+ Usually, schemas marked with 'no refresh' is not built, use --force to
82
+ rebuild all schemas
83
+
81
84
  make! -t,time --dump=KIND? -- [SCHEMA]
82
85
  @ Only rebuild changed files
83
86
 
@@ -180,7 +183,8 @@ begin
180
183
 
181
184
  when :build!
182
185
  dump = cmd.dump? ? cmd.dump("batches").to_sym : nil
183
- Prick::SubCommand.build(database, username, args.expect(0..1), timer: cmd.time?, dump: dump)
186
+ Prick::SubCommand.build(
187
+ database, username, args.expect(0..1), force: cmd.force?, timer: cmd.time?, dump: dump)
184
188
 
185
189
  when :make!
186
190
  dump = cmd.dump? ? cmd.dump("batches").to_sym : nil
data/lib/builder/batch.rb CHANGED
@@ -102,11 +102,12 @@ module Prick
102
102
  files = nodes.map(&:path)
103
103
 
104
104
  # Load meta object
105
- meta = PgMeta.new(conn)
105
+ meta = PgMeta.new(conn, exclude_schemas: builder.pg_graph_ignore_schemas)
106
106
 
107
107
  # Create type object
108
108
  type = PgGraph::Type.new(meta, builder.reflections_file)
109
109
 
110
+ # Timer
110
111
  t_type.stop
111
112
  t_fox = Timer.new " Parse files"
112
113
 
@@ -126,6 +127,7 @@ module Prick
126
127
  # Dump state file
127
128
  fox.write_state(FOX_STATE_PATH)
128
129
 
130
+ # Timer
129
131
  t_fox.stop
130
132
  t_exe = Timer.new " Execute SQL"
131
133
 
@@ -31,9 +31,12 @@ module Prick
31
31
  # Pool of nodes. Initialized by #load_pool
32
32
  attr_reader :pool
33
33
 
34
- forward_to :pool, :nodes, :decl_nodes, :init_nodes, :term_nodes,
34
+ forward_to :pool, :schemas,
35
+ :nodes, :decl_nodes, :init_nodes, :term_nodes,
35
36
  :seed_nodes, :fox_seed_nodes, :sql_seed_nodes,
36
- :schemas
37
+ :builder_nodes,
38
+ :pg_graph_ignore_schemas,
39
+ :refresh_schemas, :keep_schemas
37
40
 
38
41
  def batches() @batches ||= group end
39
42
 
@@ -90,6 +93,8 @@ module Prick
90
93
  def execute(conn, create_schemas: schemas)
91
94
  group if batches.nil?
92
95
  conn.exec create_schemas.grep_v("public").map { |schema| "create schema #{schema}" }
96
+ conn.schema.create("public", authorization: "postgres")
97
+ conn.exec "grant all on schema public to public"
93
98
  for batch in batches
94
99
  batch.execute
95
100
  end
data/lib/builder/node.rb CHANGED
@@ -142,6 +142,7 @@ module Prick
142
142
  end
143
143
  end
144
144
 
145
+ # A build.yml file node
145
146
  class BuildNode < Node
146
147
  def nodes() @nodes ||= init_nodes + decl_nodes + seed_nodes + term_nodes end
147
148
 
@@ -150,12 +151,17 @@ module Prick
150
151
  attr_reader :term_nodes
151
152
  attr_reader :seed_nodes
152
153
 
154
+ attr_accessor :pg_graph_ignore_schema
155
+ attr_accessor :refresh_schema
156
+
153
157
  def initialize(parent, path)
154
158
  super(parent, nil, :yml, path)
155
159
  @decl_nodes = []
156
160
  @init_nodes = []
157
161
  @term_nodes = []
158
162
  @seed_nodes = []
163
+ @pg_graph_ignore_schema = false
164
+ @refresh_schema = true
159
165
  end
160
166
 
161
167
  def inspect() to_s end
@@ -164,6 +170,7 @@ module Prick
164
170
  puts "BuildNode #{path}"
165
171
  indent {
166
172
  puts "schema: #{schema}" if schema
173
+ puts "pg_graph_ignore_schema: #{pg_graph_ignore_schema}"
167
174
  decl_nodes.each(&:dump)
168
175
  for kind in [:init, :term, :seed]
169
176
  kind_nodes = self.send("#{kind}_nodes".to_sym)
@@ -7,6 +7,9 @@ module Prick
7
7
 
8
8
  attr_reader :nodes
9
9
 
10
+ # All nodes including nodes deleted later on
11
+ attr_reader :all_nodes
12
+
10
13
  attr_reader :init_nodes
11
14
  attr_reader :decl_nodes
12
15
  attr_reader :seed_nodes
@@ -18,6 +21,26 @@ module Prick
18
21
  def fox_seed_nodes() seed_nodes.select { |node| node.kind == :fox } end
19
22
  def sql_seed_nodes() seed_nodes.select { |node| node.kind == :sql } end
20
23
 
24
+ # List of BuildNode nodes
25
+ def build_nodes() nodes.select { |node| node.is_a?(BuildNode) } end
26
+
27
+ # List of schemas to ignore when building PgGraph objects. This is used
28
+ # to exclude foreign schemes that doesn't follow the PgGraph naming
29
+ # conventions
30
+ def pg_graph_ignore_schemas()
31
+ all_nodes.select { |node|
32
+ node.is_a?(BuildNode) && node.pg_graph_ignore_schema
33
+ }.map(&:schema).uniq
34
+ end
35
+
36
+ def refresh_schemas()
37
+ build_nodes.select(&:refresh_schema).map(&:schema).uniq
38
+ end
39
+
40
+ def keep_schemas()
41
+ build_nodes.reject(&:refresh_schema).map(&:schema).uniq
42
+ end
43
+
21
44
  def initialize()
22
45
  self.clear
23
46
  end
@@ -25,6 +48,7 @@ module Prick
25
48
  def add(*nodes)
26
49
  nodes = Array(nodes).flatten
27
50
  @nodes.concat(nodes)
51
+ @all_nodes.concat(nodes)
28
52
  nodes.each { |node|
29
53
  @schemas[node.schema] += 1
30
54
  @kind_nodes[node.phase]&.append(node)
@@ -65,6 +89,7 @@ module Prick
65
89
  else
66
90
  @schemas = Hash.new(0) # map from schema name to number of nodes
67
91
  @nodes = []
92
+ @all_nodes = []
68
93
  @init_nodes = []
69
94
  @decl_nodes = []
70
95
  @seed_nodes = []
@@ -50,7 +50,10 @@ module Prick
50
50
  entry.each { |key, value|
51
51
  if key == "schema"
52
52
  unit.schema = value
53
- # @schemas[unit.schema = value] = true
53
+ elsif key == "standard"
54
+ unit.pg_graph_ignore_schema = !value
55
+ elsif key == "refresh"
56
+ unit.refresh_schema = value
54
57
  else
55
58
  case key
56
59
  when "init"; unit.init_nodes
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.20.12"
4
+ VERSION = "0.20.15"
5
5
  end
@@ -3,24 +3,49 @@
3
3
  require 'builder/builder.rb'
4
4
 
5
5
  module Prick::SubCommand
6
- def self.build(database, username, schema, builddir: "schema", timer: nil, dump: nil)
6
+ def self.build(database, username, schema, builddir: "schema", force: false, timer: nil, dump: nil)
7
7
  Timer.on! if timer
8
8
  time "Prick::Command#build" do
9
9
  begin
10
10
  super_conn = PgConn.new
11
+
11
12
  conn = nil
12
13
  builder = nil
13
-
14
14
  time "Load build object" do
15
15
  if super_conn.rdbms.exist? database
16
16
  conn = PgConn.new(database, username)
17
- super_conn.rdbms.empty!(database)
17
+ exist = true
18
18
  else
19
19
  super_conn.rdbms.create database, owner: username
20
20
  conn = PgConn.new(database, username)
21
+ exit = false
21
22
  end
22
23
 
23
24
  builder = Prick::Build::Builder.new(conn, builddir)
25
+
26
+ if exist
27
+ if force
28
+ builder.schemas.each { |schema| conn.schema.drop schema, cascade: true }
29
+
30
+ else
31
+ # Explicit schema is always rebuilt
32
+ refresh = [builder.refresh_schemas, schema].compact.flatten.uniq
33
+ keep = builder.keep_schemas.reject { |s| s == schema }
34
+
35
+ # Rebuild non-existing keep-schemas
36
+ keep.reject! { |schema|
37
+ refresh << schema if !conn.schema.exist?(schema)
38
+ }
39
+
40
+ # Eliminate keep schemas from build pool
41
+ builder.pool.delete_schema(keep)
42
+
43
+ # Drop refresh schemes
44
+ refresh.each { |schema| conn.schema.drop(schema, cascade: true) }
45
+ end
46
+ end
47
+
48
+ # Delete schemas after target scheme if present
24
49
  builder.pool.delete_schema(builder.pool.after_schema(schema)) if schema
25
50
  end
26
51
 
data/prick.gemspec CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "bootsnap"
37
37
  spec.add_dependency "fixture_fox", "~> 0.1.3"
38
38
  spec.add_dependency "postspec"
39
- spec.add_dependency "pg_graph", "~> 0.1.7"
39
+ spec.add_dependency "pg_graph", "~> 0.1.8"
40
40
  spec.add_dependency "shellopts", "~> 2.0.23"
41
41
 
42
42
  spec.add_development_dependency "ruby-prof"
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.20.12
4
+ version: 0.20.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-19 00:00:00.000000000 Z
11
+ date: 2022-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.1.7
117
+ version: 0.1.8
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.1.7
124
+ version: 0.1.8
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: shellopts
127
127
  requirement: !ruby/object:Gem::Requirement