prick 0.29.2 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/TODO +2 -0
  3. data/exe/prick +290 -518
  4. data/lib/prick/builder/batch.rb +1 -4
  5. data/lib/prick/builder/builder.rb +15 -9
  6. data/lib/prick/builder/node.rb +3 -2
  7. data/lib/prick/builder/node_pool.rb +3 -1
  8. data/lib/prick/builder/parser.rb +2 -1
  9. data/lib/prick/constants.rb +12 -12
  10. data/lib/prick/diff.rb +2 -2
  11. data/lib/prick/environment.rb +23 -10
  12. data/lib/prick/local/command.rb +8 -2
  13. data/lib/prick/local/fmt.rb +56 -0
  14. data/lib/prick/prick_version.rb +1 -1
  15. data/lib/prick/share/init/{.gitignore → dot.gitignore} +1 -1
  16. data/lib/prick/share/init/prick.environment.yml +16 -0
  17. data/lib/prick/share/init/prick.yml +3 -3
  18. data/lib/prick/share/init/schema/prick/build.yml +11 -2
  19. data/lib/prick/share/init/schema/prick/tables.sql +30 -9
  20. data/lib/prick/share/init/schema/prick/views.sql +6 -0
  21. data/lib/prick/state.rb +297 -95
  22. data/lib/prick/subcommand/prick-build.rb +26 -20
  23. data/lib/prick/subcommand/prick-clean.rb +5 -5
  24. data/lib/prick/subcommand/prick-create.rb +41 -6
  25. data/lib/prick/subcommand/prick-drop.rb +57 -14
  26. data/lib/prick/subcommand/prick-fox.rb +1 -1
  27. data/lib/prick/subcommand/prick-init.rb +25 -18
  28. data/lib/prick/subcommand/prick-list.rb +99 -0
  29. data/lib/prick/subcommand/prick-make.rb +8 -8
  30. data/lib/prick/subcommand/prick-migrate.rb +8 -7
  31. data/lib/prick/subcommand/prick-release.rb +4 -2
  32. data/lib/prick/subcommand/prick-set.rb +52 -0
  33. data/lib/prick/subcommand/prick-setup.rb +3 -13
  34. data/lib/prick/subcommand/prick-teardown.rb +13 -9
  35. data/lib/prick/subcommand/subcommand.rb +12 -0
  36. data/lib/prick/version.rb +1 -1
  37. data/lib/prick.rb +54 -15
  38. metadata +9 -5
  39. data/lib/prick/share/init/schema/prick/data.sql +0 -6
  40. data/prick.environments.yml +0 -14
@@ -3,28 +3,71 @@
3
3
  require_relative '../builder/builder.rb'
4
4
 
5
5
  module Prick::SubCommand
6
- def self.drop_user(username) # No database so does not cascade
7
- PgConn.new("postgres") { |conn|
8
- conn.role.drop([username])
9
- }
6
+ # Drop database owner
7
+ def self.drop_owner(username)
8
+ # No database at this point so no session is running and no cascade. A nop
9
+ # if the user is the current user or owns objects in other databases
10
+ if username != ENV['USER']
11
+ super_conn.role.drop(username, fail: false, silent: true)
12
+ end
10
13
  end
11
14
 
12
- # Drop all users associated with the given database except the owner
15
+ # Drop all users associated with the given database except the owner. We
16
+ # assume that users can only be connected to the project database and that
17
+ # they don't own objects in other databases
13
18
  def self.drop_users(database)
14
- PgConn.new(database) { |conn|
15
- users = conn.role.list(database: database)
16
- conn.role.drop(users, cascade: true)
17
- }
19
+ constrain database, String
20
+ conn = super_conn
21
+ if conn.rdbms.exist? database
22
+ users = conn.role.list(database: database).reject { _1 == conn.rdbms.owner(database) }
23
+ conn.session.terminate(database, users)
24
+ if conn.rdbms.exist?(database)
25
+ # Connect to database to make cascade work. Run in a block to close connection afterwards
26
+ PgConn.new(database) { |conn| conn.role.drop(users, cascade: true) }
27
+ else
28
+ conn.rdbms.role.drop(users)
29
+ end
30
+ else
31
+ # We don't terminate sessions because we assume one-database-users
32
+ conn.role.drop(users, cascade: true) # Fails if the users owns objects in other databases
33
+ end
18
34
  end
19
35
 
36
+ # Drop a database
20
37
  def self.drop_database(database)
21
- PgConn.new("postgres") { |conn| conn.rdbms.drop database }
38
+ State.connection.session.terminate(database, nil)
39
+ State.connection { |conn| conn.rdbms.drop database }
22
40
  end
23
41
 
24
- def self.drop_all(database)
25
- drop_users(database)
26
- drop_database(database)
27
- drop_user(username)
42
+ # Empty the database
43
+ def self.drop_schema(database, schemas = [])
44
+ constrain database, String
45
+ constrain schemas, [String]
46
+ if schemas.empty?
47
+ State.connection { |conn| conn.rdbms.empty!(database) }
48
+ else
49
+ Prick.state.connection { |conn|
50
+ schemas.each { |schema| conn.schema.drop(schema, cascade: true) }
51
+ }
52
+ end
53
+ 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
+ }
28
71
  end
29
72
  end
30
73
 
@@ -37,7 +37,7 @@ __END__
37
37
  when :batches; builder.dump
38
38
  when nil;
39
39
  else
40
- raise Prick::Error, "Illegal dump type: #{dump.inspect}"
40
+ Prick.error "Illegal dump type: #{dump.inspect}"
41
41
  end && exit
42
42
 
43
43
  time "Execute build object" do
@@ -1,46 +1,53 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module Prick::SubCommand
4
- def self.init(dir, name, title, database, username)
4
+ def self.init(project_file, dir, name, title) # dir, name, and title can be nil
5
+ cwd = Dir.getwd
5
6
  if dir
6
- !File.exist?(dir) or raise Prick::Error, "Directory #{dir} exists"
7
+ !File.exist?(dir) or Prick.error "Directory #{dir} exists"
7
8
  FileUtils.mkdir_p(dir)
8
9
  Dir.chdir(dir)
9
10
  else
10
11
  dir = "."
11
12
  end
12
- name ||= File.basename(Dir.getwd)
13
- title ||= name
14
- database ||= name
15
- username ||= name
13
+ dirname = File.basename(Dir.getwd)
14
+ name ||= dirname
15
+ title ||= name.gsub(/[_-]/, " ").capitalize
16
16
 
17
+ # Note that the initial project file is invalid and is removed again after
18
+ # the initial commit
17
19
  Command.command %(
18
20
  git init .
19
- cp -a #{SHARE_PATH}/init/. .
21
+ dir=#{SHARE_PATH}/init
22
+ for path in $dir/*; do
23
+ source_file=$(basename $path)
24
+ dest_file=$(sed 's/^dot\././' <<<$source_file)
25
+ cp -a $dir/$source_file $dest_file
26
+ done
20
27
  git add .
21
28
  git commit -am "Initial import"
29
+ rm -f #{project_file}
22
30
  ), fail: false
31
+ Command.status == 0 or Prick.failure "Failed creating initial import"
23
32
 
24
- Command.status == 0 or raise Prick::Fail, "Init script failed"
25
-
26
- state = State.new
33
+ # Write (valid) configuration file
34
+ state = State.new(project_file, nil, nil)
27
35
  state.name = name
28
36
  state.title = title
29
37
  state.prick_version = PrickVersion.new VERSION
30
38
  state.version = PrickVersion.new("0.0.0")
31
- state.environment = :development
32
- state.database = database
33
- state.username = username
34
- state.save
39
+ state.save_project
35
40
 
41
+ # Commit configuration file and create initial release
36
42
  Command.command %(
37
43
  set -e
44
+ git add #{project_file}
38
45
  git commit -am "Release 0.0.0"
39
- git tag v0.0.0
46
+ git tag --message "Initial Release" v0.0.0
40
47
  ), fail: false
48
+ Command.status == 0 or Prick.failure "Failed creating initial release"
41
49
 
42
- Command.status == 0 or raise Prick::Fail, "Init script failed"
43
-
44
- [dir, state]
50
+ Dir.chdir(cwd)
51
+ [dir, name]
45
52
  end
46
53
  end
@@ -0,0 +1,99 @@
1
+ module Prick::SubCommand
2
+ def self.list_environments(format: :long)
3
+ environments = Environment.environments.select { |env| env.comment }
4
+ if format == :short
5
+ puts environments.map(&:name)
6
+ else
7
+ headers = %w(Environment Description)
8
+ rows = environments.map { |env| [env.name, env.comment] }
9
+ Fmt.puts_table(headers, rows)
10
+ end
11
+ end
12
+
13
+ def self.list_variables(format: :long, all: false)
14
+ if format == :short
15
+ puts Prick.state.bash_environment.keys
16
+ else
17
+ headers = %w(variable value)
18
+ vars = Prick.state.bash_environment(all: all).reject { |k,v| k == "PATH" }
19
+ rows = vars.map { |k,v| [k, Array(v).flatten.join(" ")] }
20
+ Fmt.puts_table(headers, rows)
21
+ end
22
+ end
23
+
24
+ def self.list_databases(format: :long)
25
+ constrain format, :long, :short
26
+ conn = State.connection
27
+ # databases = conn.values "select datname from pg_database where datistemplate = false order by datname;"
28
+
29
+ if format == :short
30
+ puts Prick.databases
31
+ else
32
+ fs_time = `find . -type f -not -path '*/\.*' -printf '%TF %TT\n' | sort -r | head -n 1`
33
+ git_branch = Git.branch.current
34
+ git_rev = Git.id[0...8]
35
+
36
+ rows = []
37
+ Prick.databases { |database, conn|
38
+ row = conn.record(%(
39
+ select
40
+ '#{database}' as "database", name, version, branch, rev, clean, environment,
41
+ to_char(
42
+ built_at at time zone 'UTC' at time zone current_setting('TimeZone'),
43
+ 'YYYY-MM-DD HH24:MI') as "built_at",
44
+ success
45
+ from prick.versions
46
+ ))
47
+
48
+ if row[:success]
49
+ clean = row[:clean]
50
+ same_revision = row[:branch] == git_branch && row[:rev] == git_rev
51
+ up2date = fs_time <= row[:built_at]
52
+ row[:state] =
53
+ case [clean, same_revision, up2date]
54
+ in [true, true, true]; "clean" # Clean repo
55
+ in [true, true, false]; "dirty" # Clean repo but doesn't include latest changes
56
+ in [true, false, _]; "detached" # Clean repo but different revision
57
+
58
+ in [false, true, true]; "ok" # Dirty repo
59
+ in [false, true, false]; "dirty" # Dirty repo, but doesn't include latest changes
60
+ in [false, false, _]; "stale" # Dirty repo, no way back
61
+ end
62
+ else
63
+ row[:state] = "-"
64
+ end
65
+
66
+ last_column = (Prick.state.database == database ? "*" : "")
67
+ rows << row.values + [last_column]
68
+ }
69
+
70
+ headers = %w(database project version branch rev clean environment built success state) + [" "]
71
+ Fmt.puts_table(headers, rows)
72
+ end
73
+ end
74
+
75
+ def self.list_users
76
+ puts State.connection.role.list(database: Prick.state.database)
77
+ end
78
+
79
+ def self.list_owners(format: :long)
80
+ owners = {}
81
+ Prick.databases.each { |database|
82
+ # owner = super_conn.rdbms.exist?(d) ? super_conn.rdbms.owner(d) : d
83
+ owner = super_conn.rdbms.owner(database)
84
+ (owners[owner] ||= []) << database
85
+ }
86
+ if format == :short
87
+ puts owners.keys
88
+ else
89
+ headers = %w(username databases) + [" "]
90
+ rows = owners.map { |owner, databases|
91
+ current_user_mark = (Prick.state.username == owner ? '*' : "")
92
+ [owner, databases.join(","), current_user_mark]
93
+ }
94
+ Fmt.puts_table(headers, rows)
95
+ end
96
+ end
97
+ end
98
+
99
+
@@ -7,22 +7,22 @@ module Prick::SubCommand
7
7
  Timer.on! if timer
8
8
  time "Prick::Command#make" do
9
9
  begin
10
- super_conn = PgConn.new
10
+ super_conn = State.connection
11
11
  conn = nil
12
12
  builder = nil
13
- built_at = EPOCH
13
+ last_built_at = EPOCH
14
14
  clean = false
15
15
  create_schemas = []
16
16
 
17
17
  time "Load build object" do
18
18
  if super_conn.rdbms.exist? database
19
- conn = PgConn.new(database, username)
20
- if conn.schema.exist_table?("prick", "versions") && !conn.empty?("prick.versions")
21
- built_at = conn.value("select built_at from prick.versions")
19
+ conn = Prick.state.connection
20
+ if conn.schema.exist_relation?("prick", "versions") && !conn.empty?("prick.versions")
21
+ last_built_at = conn.value("select built_at from prick.versions")
22
22
  end
23
23
  else
24
24
  super_conn.rdbms.create database, owner: username
25
- conn = PgConn.new(database, username)
25
+ conn = Prick.state.connection
26
26
  clean = true
27
27
  end
28
28
 
@@ -43,7 +43,7 @@ module Prick::SubCommand
43
43
  after_schemas.each { |delete_schema| builder.pool.delete_schema(delete_schema) }
44
44
  end
45
45
 
46
- touched_nodes = builder.nodes.select { |node| File.mtime(node.path) > built_at }
46
+ touched_nodes = builder.nodes.select { |node| File.mtime(node.path) > last_built_at }
47
47
  touched_phases = touched_nodes.map(&:phase).uniq.compact
48
48
  touched_kinds = touched_nodes.map(&:kind).uniq.compact
49
49
  touched_schema = touched_nodes.first&.schema
@@ -74,7 +74,7 @@ module Prick::SubCommand
74
74
  when :batches; builder.dump
75
75
  when nil;
76
76
  else
77
- raise Prick::Error, "Illegal dump type: #{dump.inspect}"
77
+ Prick.error "Illegal dump type: #{dump.inspect}"
78
78
  end
79
79
  exit if dump
80
80
 
@@ -3,12 +3,13 @@ module Prick
3
3
  module SubCommand
4
4
  # def self.migrate(database, username, file) TODO
5
5
  def self.migrate(database, username, file: nil)
6
- PgConn.new(database, username) { |conn|
6
+ conn = Prick.state.connection
7
+ # PgConn.new(database, username) { |conn|
7
8
  conn.schema.exist_relation? "prick", "versions" or
8
- raise Prick::Fail, "Can't read version from database"
9
+ Prick.failure "Can't read version from database"
9
10
 
10
11
  from_version = PrickVersion.new(conn.value "select version from prick.versions") or
11
- raise Prick::Fail, "Illegal version in table prick.versions"
12
+ Prick.failure "Illegal version in table prick.versions"
12
13
 
13
14
  if file
14
15
  conn.transaction {
@@ -16,12 +17,12 @@ module Prick
16
17
  }
17
18
  else
18
19
  to_version = Prick.state.version
19
- from_version != to_version or raise Prick::Fail, "Already up to date"
20
- from_version < to_version or raise Prick::Fail, "Can't migrate backwards"
20
+ from_version != to_version or Prick.failure "Already up to date"
21
+ from_version < to_version or Prick.failure "Can't migrate backwards"
21
22
 
22
23
  migration_dir = "#{MIGRATION_DIR}/#{from_version}"
23
24
  File.directory? migration_dir or
24
- raise Prick::Fail, "Can't migrate from #{from_version} to #{to_version}"
25
+ Prick.failure "Can't migrate from #{from_version} to #{to_version}"
25
26
 
26
27
  puts "Migrating from #{from_version} to #{to_version}"
27
28
 
@@ -31,7 +32,7 @@ module Prick
31
32
  conn.exec File.read(SCHEMA_VERSION_PATH)
32
33
  }
33
34
  end
34
- }
35
+ # }
35
36
  end
36
37
  end
37
38
  end
@@ -8,15 +8,17 @@ module Prick
8
8
  Git.synchronized? or raise "Won't release: Repository is not synchronized with origin"
9
9
 
10
10
  version = Prick.state.version.increment!(kind).to_s
11
- Prick.state.save
11
+ Prick.state.save_project
12
12
 
13
- Git.add(Prick.state.file)
13
+ Git.add(Prick.state.project_file)
14
14
  Git.add(Prick.state.schema_file)
15
15
  Git.commit "Release #{version}"
16
16
  Git.tag.create "v#{version}"
17
17
  Git.branch.create version
18
18
  Git.push
19
19
 
20
+ # TODO TODO TODO
21
+
20
22
  puts version
21
23
  end
22
24
  end
@@ -0,0 +1,52 @@
1
+ require 'time' # For Time#parse
2
+
3
+ module Prick::SubCommand
4
+ def self.set(variable, value = nil, arg = nil)
5
+ case variable
6
+ when "database"; set_database(value, arg)
7
+ when "environment"; set_environment(value)
8
+ when "duration"; set_duration(value)
9
+ else
10
+ return false
11
+ end
12
+ true
13
+ end
14
+
15
+ def self.set_environment(environment)
16
+ if environment
17
+ Prick.state.environment = environment
18
+ Prick.state.save_state
19
+ else
20
+ puts Prick.state.environment
21
+ end
22
+ end
23
+
24
+ # If the environment is nil, it is initialized from the database on next build
25
+ def self.set_database(database, environment = nil)
26
+ if database
27
+ conn = State.connection
28
+ conn.rdbms.exist? database or Prick.error "Database '#{database}' does not exist"
29
+ username = conn.rdbms.owner database
30
+
31
+ Prick.state.database = database
32
+ Prick.state.username = username
33
+
34
+ if environment.nil?
35
+ Prick.state.connection # Implicitly initialize database enviroment if present
36
+ environment = Prick.state.database_environment # or Prick.error "Can't find environment"
37
+ end
38
+ Prick.state.environment = environment
39
+ Prick.state.save_state
40
+ else
41
+ puts Prick.state.database
42
+ end
43
+ end
44
+
45
+ def self.set_duration(make_start)
46
+ conn = Prick.state.connection
47
+ built_at = conn.value "select built_at from prick.versions"
48
+ duration = Time.now - Time.iso8601(make_start)
49
+ conn.exec "update prick.versions set make_duration = #{duration}"
50
+ end
51
+ end
52
+
@@ -3,18 +3,8 @@
3
3
  require_relative '../builder/builder.rb'
4
4
 
5
5
  module Prick::SubCommand
6
- def self.setup(database, username)
7
- conn = PgConn.new("template1") # Connect to template1 because database might not exist
8
- if !conn.role.exist? username
9
- # FIXME Should not be created as superuser but we can't do that before we
10
- # have a super: option in build
11
- conn.role.create username, superuser: true, can_login: true, create_role: true
12
- end
13
- if !conn.rdbms.exist? database
14
- conn.rdbms.create database, owner: username
15
- end
16
- builder = Prick::Build::Builder.new(conn, "schema")
17
- # TODO Run builder setup scrips
6
+ def self.setup(database, username, environment)
7
+ create_database(database, username, environment)
8
+ set_database(database, environment)
18
9
  end
19
10
  end
20
-
@@ -3,17 +3,21 @@
3
3
  require_relative '../builder/builder.rb'
4
4
 
5
5
  module Prick::SubCommand
6
- def self.teardown(database, username)
7
- conn = PgConn.new "postgres" # Superuser connection
8
- if conn.rdbms.exist? database
9
- conn.rdbms.drop database, force: true
10
- end
11
- if conn.role.exist? username
12
- conn.role.drop username, cascade: true
13
- end
6
+ def self.teardown(*databases, remove_state_file: false)
7
+ databases = Array(databases).flatten
8
+ owners = databases.map { |d|
9
+ super_conn.rdbms.exist?(d) ? super_conn.rdbms.owner(d) : d
10
+ }.uniq
11
+ users = databases.map { |d| super_conn.role.list(database: d) }.flatten.uniq
12
+
13
+ databases.each { |d| drop_database(d) }
14
+ super_conn.role.drop(users)
15
+ super_conn.role.drop(owners, fail: false)
16
+ owners.each { |o| drop_owner(o) }
17
+
18
+ FileUtils.rm_f Prick.state.state_file if remove_state_file
14
19
 
15
20
  # TODO Run builder teardown scrips
16
- # builder = Prick::Build::Builder.new(conn, "schema")
17
21
  end
18
22
  end
19
23
 
@@ -0,0 +1,12 @@
1
+ module Prick::Subcommand
2
+ # def self.parse_username_database
3
+ # case username_database
4
+ # when nil
5
+ # [nil, nil]
6
+ # when username_database =~ /^(.*)@(.*)$/
7
+ # [$1, $2]
8
+ # else
9
+ # [username_database, username_database]
10
+ # end
11
+ # end
12
+ end
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.29.2"
4
+ VERSION = "0.30.0"
5
5
  end
data/lib/prick.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'prick/version.rb'
1
+ require 'prick/version.rb'
2
2
 
3
3
  require 'pg_conn'
4
4
 
@@ -8,7 +8,7 @@ require 'constrain'
8
8
 
9
9
  module Prick
10
10
  class Error < RuntimeError; end
11
- class Fail < RuntimeError; end
11
+ class Failure < RuntimeError; end
12
12
  end
13
13
 
14
14
  require_relative 'prick/constants.rb'
@@ -18,6 +18,7 @@ require_relative 'prick/local/command.rb'
18
18
  require_relative 'prick/local/git.rb'
19
19
  require_relative 'prick/local/timer.rb'
20
20
  require_relative 'prick/local/ansi.rb'
21
+ require_relative 'prick/local/fmt.rb'
21
22
 
22
23
  require_relative 'prick/environment.rb'
23
24
  require_relative 'prick/state.rb'
@@ -25,27 +26,65 @@ require_relative 'prick/prick_version.rb'
25
26
  require_relative 'prick/diff.rb'
26
27
 
27
28
  module Prick
28
- module SubCommand
29
- extend Timer
30
- def self.mesg(*msgs) puts msgs.join(" ") if !$quiet end
31
- def self.verb(*msgs) puts msgs.join(" ") if $verbose && !$quiet end
32
- end
29
+ def mesg(*msgs) = Prick.mesg(*msgs)
30
+ def verb(*msgs) = Prick.verb(*msgs)
31
+ def self.mesg(*msgs) puts msgs.join(" ") if !$quiet end
32
+ def self.verb(*msgs) puts msgs.join(" ") if $verbose && !$quiet end
33
33
  end
34
34
 
35
- require_relative 'prick/subcommand/prick-init.rb'
36
- require_relative 'prick/subcommand/prick-setup.rb'
37
- require_relative 'prick/subcommand/prick-teardown.rb'
35
+ require_relative 'prick/subcommand/subcommand.rb'
36
+ require_relative 'prick/subcommand/prick-build.rb'
38
37
  require_relative 'prick/subcommand/prick-clean.rb'
39
38
  require_relative 'prick/subcommand/prick-create.rb'
40
- require_relative 'prick/subcommand/prick-build.rb'
41
- require_relative 'prick/subcommand/prick-make.rb'
42
- require_relative 'prick/subcommand/prick-fox.rb'
43
39
  require_relative 'prick/subcommand/prick-drop.rb'
44
- require_relative 'prick/subcommand/prick-release.rb'
40
+ require_relative 'prick/subcommand/prick-set.rb'
41
+ require_relative 'prick/subcommand/prick-list.rb'
42
+ require_relative 'prick/subcommand/prick-fox.rb'
43
+ require_relative 'prick/subcommand/prick-init.rb'
44
+ require_relative 'prick/subcommand/prick-make.rb'
45
45
  require_relative 'prick/subcommand/prick-migrate.rb'
46
+ require_relative 'prick/subcommand/prick-release.rb'
47
+ require_relative 'prick/subcommand/prick-setup.rb'
48
+ require_relative 'prick/subcommand/prick-teardown.rb'
46
49
 
47
50
  module Prick
48
51
  @state = nil
49
- def self.state() @state end
52
+ def self.state?() !@state.nil? end
53
+ def self.state() @state or raise ArgumentError end
50
54
  def self.state=(state) @state = state end
55
+
56
+ def self.error(*args) raise Prick::Error.new *args end
57
+ def self.failure(*args) raise Prick::Failure.new *args end
58
+
59
+ def self.owner_conn = state.connection
60
+ def self.super_conn = State.connection
61
+ # def self.conn = owner_conn
62
+
63
+ # Return list of prick databases. If a block is given it is called with a
64
+ # connection to each of the databases
65
+ def self.databases(&block)
66
+ databases = super_conn.values %(
67
+ select datname from pg_database where datistemplate = false order by datname
68
+ )
69
+ databases.select! { |database|
70
+ PgConn.new(database) { |conn|
71
+ is_prick_database = conn.exist?(%(
72
+ select 1
73
+ from information_schema.tables
74
+ where table_schema = 'prick'
75
+ and table_name = 'builds'
76
+ limit 1
77
+ ))
78
+ yield(database, conn) if is_prick_database && block_given?
79
+ is_prick_database
80
+ }
81
+ }
82
+ databases
83
+ end
84
+
85
+ module SubCommand
86
+ def self.owner_conn = Prick.owner_conn
87
+ def self.super_conn = Prick.super_conn
88
+ # def self.conn = Prick.conn
89
+ end
51
90
  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.29.2
4
+ version: 0.30.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-01-24 00:00:00.000000000 Z
11
+ date: 2024-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic
@@ -194,19 +194,21 @@ files:
194
194
  - lib/prick/ext/expand_variables.rb
195
195
  - lib/prick/local/ansi.rb
196
196
  - lib/prick/local/command.rb
197
+ - lib/prick/local/fmt.rb
197
198
  - lib/prick/local/git.rb
198
199
  - lib/prick/local/timer.rb
199
200
  - lib/prick/prick_version.rb
200
- - lib/prick/share/init/.gitignore
201
201
  - lib/prick/share/init/.rspec
202
+ - lib/prick/share/init/dot.gitignore
202
203
  - lib/prick/share/init/migration/.keep
204
+ - lib/prick/share/init/prick.environment.yml
203
205
  - lib/prick/share/init/prick.yml
204
206
  - lib/prick/share/init/schema/.keep
205
207
  - lib/prick/share/init/schema/build.yml
206
208
  - lib/prick/share/init/schema/prick/.keep
207
209
  - lib/prick/share/init/schema/prick/build.yml
208
- - lib/prick/share/init/schema/prick/data.sql
209
210
  - lib/prick/share/init/schema/prick/tables.sql
211
+ - lib/prick/share/init/schema/prick/views.sql
210
212
  - lib/prick/share/init/schema/public/.keep
211
213
  - lib/prick/share/init/spec/prick_helper.rb
212
214
  - lib/prick/share/init/spec/prick_spec.rb
@@ -222,13 +224,15 @@ files:
222
224
  - lib/prick/subcommand/prick-drop.rb
223
225
  - lib/prick/subcommand/prick-fox.rb
224
226
  - lib/prick/subcommand/prick-init.rb
227
+ - lib/prick/subcommand/prick-list.rb
225
228
  - lib/prick/subcommand/prick-make.rb
226
229
  - lib/prick/subcommand/prick-migrate.rb
227
230
  - lib/prick/subcommand/prick-release.rb
231
+ - lib/prick/subcommand/prick-set.rb
228
232
  - lib/prick/subcommand/prick-setup.rb
229
233
  - lib/prick/subcommand/prick-teardown.rb
234
+ - lib/prick/subcommand/subcommand.rb
230
235
  - lib/prick/version.rb
231
- - prick.environments.yml
232
236
  - prick.gemspec
233
237
  homepage: http://www.nowhere.com/
234
238
  licenses: []
@@ -1,6 +0,0 @@
1
- --
2
- -- This file is auto-generated by prick(1). Please don't touch
3
- --
4
- delete from prick.versions;
5
- insert into prick.versions (fork, major, minor, patch, pre, feature, version)
6
- values (null, 0, 0, 0, null, null, '0.0.0');