prick 0.30.0 → 0.31.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: 7302ba57c3bed137c90862b29e2a2b14938395963a3521aa10a2b096d516696f
4
- data.tar.gz: f7d7e31e0f24c4346bffff6d03d104c7f8e9e9f2605bde0a6f67f48a16736499
3
+ metadata.gz: 71425ed90edd4de504fc95a6d270a5659c0ff206710db81c4994b03af76931e9
4
+ data.tar.gz: 3c5454cc8052d994257dba637285088352196f7bb522dd16fb19e4d43cafe3b8
5
5
  SHA512:
6
- metadata.gz: 3e1fb9a5b8a9befdd1367b6653dd46dc0df0ca17ce94a15153f4d590390b1341c5930ffbc2a5608cdf906b0d22e56aaf1782c96c01ea3ffdbbbf85dc5c097f98
7
- data.tar.gz: c79a6ecd5bd77169517c6b70dca2363da933fc3f73550e390297c991a2aed4c8ac0d6887855b93112fcac2d32818f3ee5e93609d1dfedae913e53f8dc6d8d187
6
+ metadata.gz: f59c9a5ac1284eeb006327370308630ec24b3dc30dfa9af10f0695f6b0501bcfe207750b78893315f2478364eee576f780a65662d6827aa77fe2b654f5b38a8a
7
+ data.tar.gz: 7958f8d49c73c5c1b2de604fb671367c2704ef3d373c0847ae9861378f719b2e6e9d02661c8b3c36ce91541e8adb71875f3d233f7151277c64d51439087203ad
data/exe/prick CHANGED
@@ -51,7 +51,8 @@ SPEC = %(
51
51
  teardown! -- [DATABASE...] @ Remove database and owner
52
52
  Drop database, database users, and database owner if possible and not the
53
53
  current user. DATABASE defaults to the current database in which case the
54
- state file is also removed
54
+ state file is also removed. If the --force option is present, the
55
+ database is dropped even if it is not a Prick database
55
56
 
56
57
  clean! -- [DATABASE] @ Empty database and remove users
57
58
  Empty the database and drop related users except the database owner and
@@ -96,27 +97,28 @@ SPEC = %(
96
97
  create.all!
97
98
  TODO
98
99
 
99
- drop.schema! -- [SCHEMA...]
100
- @ Drop schemas
101
-
102
- Drops the given schemas or all schemas if called without arguments
103
-
104
- drop.users!
100
+ drop.users! -- [DATABASE]
105
101
  @ Drop database users
106
102
 
107
103
  Drops all database users except the database owner
108
104
 
105
+ drop.owner! -- [DATABASE]
106
+ Drop database owner
107
+
108
+ drop.database! -- [DATABASE]
109
+ Drop database
110
+
111
+ drop.schema! -- [DATABASE] [SCHEMA...]
112
+ @ Drop schemas
113
+
114
+ Drops the given schemas or all schemas if called without arguments. The
115
+ 'prick' schema is only deleted if named explicity
116
+
109
117
  drop.data!
110
118
  @ Drop data
111
119
 
112
120
  TODO
113
121
 
114
- drop.owner!
115
- Drop database owner
116
-
117
- drop.database!
118
- Drop database
119
-
120
122
  build! -f,force -t,time --dump=KIND? -- [SCHEMA]
121
123
  Build the project. If SCHEMA is defined, later schemas are excluded.
122
124
  KIND can be 'nodes', 'allnodes' or 'batches' (the default)
@@ -182,6 +184,8 @@ SPEC = %(
182
184
  read name title <<< $(prick dump value PRICK_NAME PRICK_TITLE)
183
185
 
184
186
  dump.node!
187
+ Dump build nodes
188
+
185
189
  dump.build!
186
190
  dump.data! @ TODO
187
191
  dump.schema! @ TODO
@@ -194,7 +198,7 @@ def require_db(database = Prick.state&.database, exist: true)
194
198
  dba = State.connection
195
199
  if exist
196
200
  dba.rdbms.exist?(database) or Prick.error "Can't find database '#{database}'"
197
- if Prick.state&.conn&.name == database
201
+ if Prick.state&.connection&.name == database
198
202
  close_conn = false
199
203
  conn = Prick.state.conn
200
204
  else
@@ -358,24 +362,24 @@ begin
358
362
  Prick::SubCommand.fox(database, username, args)
359
363
 
360
364
  when :drop!
361
- require_db if cmd.subcommand != :owner!
362
- if cmd.subcommand == :schema!
363
- schemas = args.to_a
364
- else
365
- args.expect(0)
366
- end
367
365
  case cmd.subcommand
368
- when :all!
369
- Prick::SubCommand.drop_all(database, username)
370
366
  when :users!
367
+ # Should set state.username to owner of database
368
+ database = state.database = args.expect(0..1) || database
369
+ username = state.username = State.connection.rdbms.owner(database)
370
+ require_db(database)
371
371
  Prick::SubCommand.drop_users(database)
372
372
  when :owner!
373
- Prick::SubCommand.drop_owner(username)
373
+ owner = args.expect(0..1) || username
374
+ Prick::SubCommand.drop_owner(owner)
374
375
  when :database!
376
+ database = args.expect(0..1) || database
375
377
  Prick::SubCommand.drop_database(database)
376
378
  when :data!
377
379
  raise NotImplementedError
378
380
  when :schema!
381
+ require_db
382
+ schemas = args.to_a
379
383
  Prick::SubCommand.drop_schema(database, schemas)
380
384
  else
381
385
  Prick.error "Unknown subject: #{subject}"
@@ -393,7 +397,7 @@ begin
393
397
  Prick::SubCommand.migrate(database, username, file: cmd.file)
394
398
 
395
399
  when :list!
396
- format = (cmd.subcommand!.long? ? :long : :short) if cmd.subcommand != :users!
400
+ format = (cmd.subcommand!.long? ? :long : :short) if cmd.subcommand && cmd.subcommand != :users!
397
401
  case cmd.subcommand
398
402
  when :environments!; Prick::SubCommand.list_environments(format: format)
399
403
  when :databases!; Prick::SubCommand.list_databases(format: format)
@@ -403,7 +407,7 @@ begin
403
407
  when :users!; Prick::SubCommand.list_users
404
408
  when :owners!; Prick::SubCommand.list_owners(format: format)
405
409
  else
406
- Prick.error "Unknown subcommand: #{cmd.subcommand}"
410
+ Prick.error "Unknown subcommand '#{cmd.subcommand || args.first }'"
407
411
  end
408
412
 
409
413
  when :dump!
@@ -439,15 +443,14 @@ begin
439
443
  Prick.error "Conflicting options - --export and --local"
440
444
  end
441
445
  puts state.bash_source(args.first ? args : nil, scope: scope)
442
- exit
443
446
  when :value!
444
447
  puts args.expect(1..).map { |var| Array(state.bash_environment[var]).join(' ') }
445
448
  else
446
449
  object = args.extract(1) # Fails if object is absent
447
450
  Prick.error "Unknown dump object: #{object}"
448
451
  end
449
- else
450
- Prick.failure "Internal error: Unhandled command - #{opts.subcommand.inspect}"
452
+ else
453
+ Prick.failure "Internal error: Unhandled command - #{opts.subcommand.inspect}"
451
454
  end
452
455
 
453
456
  rescue Prick::Build::PostgresError => ex
data/idea.txt ADDED
@@ -0,0 +1,38 @@
1
+
2
+ Build spec
3
+ Custom variables
4
+ variables VAR...
5
+
6
+ Variables
7
+ graph # old 'standard'
8
+ schema
9
+ rebuild
10
+ refresh
11
+ require
12
+
13
+ Code
14
+ build
15
+ rebuild
16
+ refresh
17
+ import
18
+ export
19
+
20
+ Special code functions
21
+ super
22
+ build file-or-directory # makes sure not to load a file twice
23
+ sql "sql statement"
24
+ use sql-file # makes sure not to load a file twice
25
+ load dump-files # makes sure not to load a file twice
26
+
27
+ build_ENVIRONMENT # eg. 'build_app_registry_backend'
28
+ rebuild_ENVIRONMENT
29
+ refresh_ENVIRONMENT
30
+
31
+ Environment variables
32
+ PRICK_ENVIRONMENTS # all environments included in the current environment
33
+
34
+ Helper functions
35
+ # Consults PRICK_ENVIRONMENTS to check if the given environment is include
36
+ # in the current environment
37
+ has_environment ENVIRONMENT
38
+
@@ -90,13 +90,18 @@ module Prick
90
90
  @@SORTED_ENVIRONMENTS = []
91
91
 
92
92
  def self.yaml_to_array(value)
93
- !value.nil? && Array(value).flatten.compact.map(&:to_s).map(&:split).flatten
93
+ case value
94
+ when /\n/; [value.split("\n")]
95
+ when nil ; []
96
+ when String; value.split
97
+ else [value.to_s]
98
+ end
99
+ # !value.nil? && Array(value).flatten.compact.map(&:to_s).map(&:split).flatten
94
100
  end
95
101
 
96
102
  def self.parse(hash)
97
103
  hash = hash.dup
98
- @@VARIABLES = [:parents, :comment] + (yaml_to_array(hash.delete("variables") || []).map(&:to_sym) || [])
99
-
104
+ @@VARIABLES = [:parents, :comment] + yaml_to_array(hash.delete("variables") || "").map(&:to_sym)
100
105
  for environment, settings in hash
101
106
  env = Environment.new(environment)
102
107
  settings ||= {}
data/lib/prick/state.rb CHANGED
@@ -106,13 +106,13 @@ module Prick
106
106
  # Project user (owner) connection. Memoized to connect only once.
107
107
  # TODO Rename. Also rename self.connection
108
108
  def connection(database: nil, username: nil, environment: nil, &block)
109
- database ||= self.database
110
- username ||= self.username
111
- environment ||= self.environment
112
- !database.nil? or Prick.error "Can't connect to Postgres - no database specified"
113
- # exist_database_environment? or Prick.error "Database '#{database}' is not initialized"
114
-
115
109
  if @connection.nil?
110
+ database ||= self.database
111
+ username ||= self.username
112
+ environment ||= self.environment
113
+ !database.nil? or Prick.error "Can't connect to Postgres - no database specified"
114
+ # exist_database_environment? or Prick.error "Database '#{database}' is not initialized"
115
+
116
116
  @connection = PgConn.new(database, username)
117
117
 
118
118
  # Set database_version/environment/prick members
@@ -193,7 +193,7 @@ module Prick
193
193
  })
194
194
 
195
195
  # PRICK_ENVIRONMENT_* variables
196
- hash.merge! (Prick.state.environment.nil? ? {} : Environment[Prick.state.environment].bash_env)
196
+ hash.merge! (Prick.state.environment.nil? ? {} : Environment[Prick.state.environment]&.bash_env || {})
197
197
  end
198
198
  end
199
199
 
@@ -210,7 +210,14 @@ module Prick
210
210
 
211
211
  (vars || bash_environment.keys).map { |var|
212
212
  val = bash_environment[var]
213
- "#{prefix}#{var}=\"#{Array(val).join(' ')}\"\n"
213
+ if val.is_a?(Array)
214
+ if val.first.is_a?(Array)
215
+ val = val.map { |v| v.join("\n") }.join("\n")
216
+ else
217
+ val = val.join(" ")
218
+ end
219
+ end
220
+ "#{prefix}#{var}=\"#{val}\"\n"
214
221
  }.join
215
222
  end
216
223
 
@@ -243,7 +250,7 @@ module Prick
243
250
  "prick.builds",
244
251
  name: name,
245
252
  version: version.to_s, prick: prick_version,
246
- branch: branch, rev: rev(:short), clean: clean?,
253
+ branch: branch, rev: rev(kind: :short), clean: clean?,
247
254
  environment: environment)
248
255
  end
249
256
  end
@@ -257,7 +264,7 @@ module Prick
257
264
  "prick.builds",
258
265
  name: name,
259
266
  version: version.to_s, prick: prick_version,
260
- branch: branch, rev: rev(:short), clean: clean?,
267
+ branch: branch, rev: rev(kind: :short), clean: clean?,
261
268
  environment: environment,
262
269
  success: success, duration: duration, prick_duration: dt)
263
270
  end
@@ -290,7 +297,7 @@ module Prick
290
297
  def load_yaml(file, mandatory_keys, optional_keys = [])
291
298
  mandatory_keys = mandatory_keys.map(&:to_s)
292
299
  optional_keys = optional_keys.map(&:to_s)
293
- hash = read_yaml(file)
300
+ hash = read_yaml(file) or Prick.error "Not a valid YAML file - #{file}"
294
301
  for key in mandatory_keys
295
302
  !hash[key].to_s.empty? or Prick.error "Can't find '#{key}' in #{file}"
296
303
  end
@@ -18,7 +18,7 @@ module Prick::SubCommand
18
18
  conn = nil
19
19
  builder = nil
20
20
 
21
- constrain super_conn.rdbms.exist?, true
21
+ constrain super_conn.rdbms.exist?(database), true # FIXME Same problem as below
22
22
 
23
23
  Timer.time "Load build object" do
24
24
  if super_conn.rdbms.exist? database # FIXME Why create database? Setup should have done this
@@ -88,7 +88,7 @@ module Prick
88
88
  }
89
89
  !diff.same? or Prick.failure "No changes"
90
90
  ensure
91
- drop_all(from_db)
91
+ drop_all(from_db) # FIXME This will fail, maybe use teardown instead?
92
92
  drop_all(to_db)
93
93
  end
94
94
  end
@@ -29,6 +29,8 @@ module Prick::SubCommand
29
29
  end
30
30
  else
31
31
  # We don't terminate sessions because we assume one-database-users
32
+ # FIXME: users is undefined
33
+ raise NotImpementedError
32
34
  conn.role.drop(users, cascade: true) # Fails if the users owns objects in other databases
33
35
  end
34
36
  end
@@ -44,30 +46,12 @@ module Prick::SubCommand
44
46
  constrain database, String
45
47
  constrain schemas, [String]
46
48
  if schemas.empty?
47
- State.connection { |conn| conn.rdbms.empty!(database) }
49
+ State.connection { |conn| conn.rdbms.empty!(database, exclude: "prick") }
48
50
  else
49
51
  Prick.state.connection { |conn|
50
52
  schemas.each { |schema| conn.schema.drop(schema, cascade: true) }
51
53
  }
52
54
  end
53
55
  end
54
-
55
- # Drop database and its users including the owner if possible and not the
56
- # current user
57
- def self.drop_all(database, username = nil)
58
- constrain database, String
59
- State.connection { |conn|
60
- if username.nil? && conn.rdbms.exist?(database)
61
- owner = State.connection.rdbms.owner(database)
62
- else
63
- owner = username || database
64
- end
65
- if conn.rdbms.exist? database
66
- drop_users(database)
67
- drop_database(database)
68
- end
69
- drop_owner(owner) if owner != ENV['USER']
70
- }
71
- end
72
56
  end
73
57
 
@@ -12,7 +12,7 @@ module Prick::SubCommand
12
12
 
13
13
  def self.list_variables(format: :long, all: false)
14
14
  if format == :short
15
- puts Prick.state.bash_environment.keys
15
+ puts Prick.state.bash_environment(all: all).keys
16
16
  else
17
17
  headers = %w(variable value)
18
18
  vars = Prick.state.bash_environment(all: all).reject { |k,v| k == "PATH" }
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.30.0"
4
+ VERSION = "0.31.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.30.0
4
+ version: 0.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-23 00:00:00.000000000 Z
11
+ date: 2024-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic
@@ -182,6 +182,7 @@ files:
182
182
  - bin/setup
183
183
  - doc/build-yml.txt
184
184
  - exe/prick
185
+ - idea.txt
185
186
  - lib/prick.rb
186
187
  - lib/prick/builder/batch.rb
187
188
  - lib/prick/builder/builder.rb
@@ -237,7 +238,7 @@ files:
237
238
  homepage: http://www.nowhere.com/
238
239
  licenses: []
239
240
  metadata: {}
240
- post_install_message:
241
+ post_install_message:
241
242
  rdoc_options: []
242
243
  require_paths:
243
244
  - lib
@@ -252,8 +253,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
253
  - !ruby/object:Gem::Version
253
254
  version: '0'
254
255
  requirements: []
255
- rubygems_version: 3.3.18
256
- signing_key:
256
+ rubygems_version: 3.3.7
257
+ signing_key:
257
258
  specification_version: 4
258
259
  summary: A release control and management system for postgresql
259
260
  test_files: []