prick 0.49.0 → 0.50.0
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/PLAN +9 -0
- data/exe/prick +7 -9
- data/lib/prick/builder/batch.rb +1 -1
- data/lib/prick/builder/builder.rb +3 -7
- data/lib/prick/subcommand/prick-build.rb +1 -9
- data/lib/prick/subcommand/prick-create.rb +14 -9
- data/lib/prick/subcommand/prick-fox.rb +0 -52
- data/lib/prick/subcommand/prick-run.rb +79 -88
- data/lib/prick/subcommand/prick-set.rb +2 -2
- data/lib/prick/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c804f1ec2c646b27750010611bac31acad4eb530500c6f77d8044b5cb703973
|
|
4
|
+
data.tar.gz: eca5f60a7af6a5e455e97541c69b373e466a9d7c7b72347d891ede3758631272
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7b5d8d62790b80d92ce16ce3a55348c5475de293aa0fec503a60668d583693c1a9c2218fdfb4f90d0be62b14ee2cc8011fa73fb29c870b03fb3374c7a50b4b57
|
|
7
|
+
data.tar.gz: aab1dc22c44a1ba6bfe66f851e307b5a0c729702c9177cdfab1a91686afccb1a5e6337c6d8e3de6ab7b08ddd43cde46e243cc4f43cadf8cec3e7b9d329888032
|
data/PLAN
ADDED
data/exe/prick
CHANGED
|
@@ -96,7 +96,7 @@ SPEC = %(
|
|
|
96
96
|
'set database' subcommand
|
|
97
97
|
|
|
98
98
|
create.prick! -- (Re-)initialize the prick schema
|
|
99
|
-
|
|
99
|
+
(Re-)create the prick schema
|
|
100
100
|
|
|
101
101
|
create.migration! -f,force -o,file=FILE -- VERSION @ Create migration
|
|
102
102
|
Create a migration from VERSION to the current and write it to
|
|
@@ -262,6 +262,7 @@ def require_db(database = Prick.state&.database, exist: true)
|
|
|
262
262
|
conn = PgConn.new(database)
|
|
263
263
|
end
|
|
264
264
|
conn.schema.exist?("prick") or Prick.error "Database '#{database}' is not a Prick database"
|
|
265
|
+
|
|
265
266
|
conn.close if close_conn # Close session explicitly so we can drop database if required
|
|
266
267
|
else
|
|
267
268
|
!dba.rdbms.exist?(database) or Prick.error "Database '#{database}' exists"
|
|
@@ -414,14 +415,11 @@ begin
|
|
|
414
415
|
require_db(database, exist: false)
|
|
415
416
|
Prick::SubCommand.create_database(database, username, environment)
|
|
416
417
|
when :prick!
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
Prick::SubCommand.
|
|
421
|
-
|
|
422
|
-
else
|
|
423
|
-
Prick::SubCommand.create_database(database, username, environment)
|
|
424
|
-
end
|
|
418
|
+
conn = PgConn.new(database, username)
|
|
419
|
+
conn.transaction {
|
|
420
|
+
conn.schema.drop("prick", cascade: true) if conn.schema.exist?("prick")
|
|
421
|
+
Prick::SubCommand.build_prick(conn, environment)
|
|
422
|
+
}
|
|
425
423
|
when :migration!
|
|
426
424
|
# clean_pg_meta_cache # FIXME ?
|
|
427
425
|
require_db
|
data/lib/prick/builder/batch.rb
CHANGED
|
@@ -156,7 +156,7 @@ module Prick
|
|
|
156
156
|
@batches
|
|
157
157
|
end
|
|
158
158
|
|
|
159
|
-
def execute(conn, create_schemas: schemas)
|
|
159
|
+
def execute(conn, create_schemas: schemas, state: true)
|
|
160
160
|
# Load pool
|
|
161
161
|
load_pool if pool.nil?
|
|
162
162
|
|
|
@@ -164,23 +164,19 @@ module Prick
|
|
|
164
164
|
create_batches if batches.nil?
|
|
165
165
|
|
|
166
166
|
# Register build in database
|
|
167
|
-
Prick.state.save_build_begin
|
|
167
|
+
Prick.state.save_build_begin if state
|
|
168
168
|
|
|
169
169
|
# Create schemas
|
|
170
170
|
conn.exec create_schemas.map { |schema| "create schema #{schema}" } if !single
|
|
171
171
|
|
|
172
172
|
# Execute batch groups
|
|
173
173
|
t0 = Time.now
|
|
174
|
-
# for batch in batches
|
|
175
|
-
# puts "Executing #{batch.class} batch"
|
|
176
|
-
# batch.execute
|
|
177
|
-
# end
|
|
178
174
|
batches.each(&:execute)
|
|
179
175
|
t1 = Time.now
|
|
180
176
|
|
|
181
177
|
# Register build result in database
|
|
182
178
|
dt = t1 - t0
|
|
183
|
-
Prick.state.save_build_end(true, dt)
|
|
179
|
+
Prick.state.save_build_end(true, dt) if state
|
|
184
180
|
end
|
|
185
181
|
|
|
186
182
|
def dump
|
|
@@ -47,7 +47,7 @@ module Prick::SubCommand
|
|
|
47
47
|
# builder.pool.delete_schema("prick") if super_conn.schema.exist?("prick")
|
|
48
48
|
# super_conn.rdbms.empty!(database, public: false, exclude: ["prick"])
|
|
49
49
|
super_conn.rdbms.empty!(database, public: false)
|
|
50
|
-
Prick::SubCommand::
|
|
50
|
+
Prick::SubCommand::create_prick(database, username)
|
|
51
51
|
else
|
|
52
52
|
# Find all schemas
|
|
53
53
|
refresh_schemas = conn.schema.list
|
|
@@ -87,17 +87,9 @@ module Prick::SubCommand
|
|
|
87
87
|
builder.execute conn
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
# rescue Prick::Error => ex
|
|
91
|
-
# $stderr.puts ex.message
|
|
92
|
-
# exit 1
|
|
93
|
-
|
|
94
90
|
rescue ::Command::Error => ex
|
|
95
91
|
$stderr.puts ex.message
|
|
96
92
|
exit 1
|
|
97
|
-
|
|
98
|
-
ensure
|
|
99
|
-
super_conn&.terminate
|
|
100
|
-
conn&.terminate
|
|
101
93
|
end
|
|
102
94
|
end
|
|
103
95
|
end
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
module Prick
|
|
2
2
|
module SubCommand
|
|
3
|
-
PRICK_BUILD_FILES = %w(tables.sql views.sql functions.sql) # FIXME FIXME FIXME HARDCODED
|
|
4
|
-
|
|
5
3
|
def self.exist_database?(database)
|
|
6
4
|
State.connection.rdbms.exist? database
|
|
7
5
|
end
|
|
@@ -21,17 +19,19 @@ module Prick
|
|
|
21
19
|
super_conn.rdbms.create database, owner: username
|
|
22
20
|
|
|
23
21
|
# Initialize prick schema
|
|
24
|
-
|
|
22
|
+
create_prick database, username, environment
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
# Setup prick schema. Used when we rebuild the prick schema without
|
|
28
26
|
# disconnecting users
|
|
29
|
-
def self.
|
|
30
|
-
#
|
|
31
|
-
# is ignored
|
|
32
|
-
conn = PgConn.new(database, username) # Can't use Prick.state.connection on a new database
|
|
27
|
+
def self.build_prick(conn, environment)
|
|
28
|
+
# Create schema
|
|
33
29
|
conn.schema.create("prick")
|
|
34
|
-
|
|
30
|
+
|
|
31
|
+
# Run prick/build.yml
|
|
32
|
+
Prick::SubCommand.run(
|
|
33
|
+
conn.database, conn.username, "schema/prick/build.yml",
|
|
34
|
+
conn: conn, state: false, seeds: false, auth: false)
|
|
35
35
|
|
|
36
36
|
# Add initial build record
|
|
37
37
|
state = Prick.state # shorthand
|
|
@@ -43,10 +43,15 @@ module Prick
|
|
|
43
43
|
rev: state.rev(kind: :short),
|
|
44
44
|
clean: state.clean?,
|
|
45
45
|
environment: environment || Prick::DEFAULT_ENVIRONMENT,
|
|
46
|
-
built_at:
|
|
46
|
+
built_at: Time.now,
|
|
47
47
|
success: nil
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
def self.create_prick(database, username, environment)
|
|
51
|
+
conn = PgConn.new(database, username)
|
|
52
|
+
build_prick(conn, environment)
|
|
53
|
+
end
|
|
54
|
+
|
|
50
55
|
def self.create_migration(username, from_version, force: false, file: nil)
|
|
51
56
|
constrain from_version, PrickVersion
|
|
52
57
|
Git.clean? or raise "Won't migrate: Repository is dirty"
|
|
@@ -19,55 +19,3 @@ module Prick::SubCommand
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
__END__
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Timer.on! if timer
|
|
26
|
-
time "Prick::Command#build" do
|
|
27
|
-
begin
|
|
28
|
-
super_conn = PgConn.new
|
|
29
|
-
conn = nil
|
|
30
|
-
builder = nil
|
|
31
|
-
|
|
32
|
-
time "Load build object" do
|
|
33
|
-
if super_conn.rdbms.exist? database
|
|
34
|
-
conn = PgConn.new(database, username)
|
|
35
|
-
super_conn.rdbms.empty!(database)
|
|
36
|
-
else
|
|
37
|
-
super_conn.rdbms.create database, owner: username
|
|
38
|
-
conn = PgConn.new(database, username)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
builder = Prick::Build::Builder.new(conn, builddir)
|
|
42
|
-
builder.pool.delete_schema(builder.pool.after_schema(schema)) if schema
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
case dump
|
|
46
|
-
when :nodes; builder.nodes.reject { |node| node.is_a?(Build::BuildNode) }.map &:dump
|
|
47
|
-
when :allnodes; builder.nodes.map &:dump
|
|
48
|
-
when :batches; builder.dump
|
|
49
|
-
when nil;
|
|
50
|
-
else
|
|
51
|
-
Prick.error "Illegal dump type: #{dump.inspect}"
|
|
52
|
-
end && exit
|
|
53
|
-
|
|
54
|
-
time "Execute build object" do
|
|
55
|
-
builder.execute conn
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
rescue Prick::Error => ex
|
|
59
|
-
$stderr.puts ex.message
|
|
60
|
-
exit 1
|
|
61
|
-
|
|
62
|
-
rescue ::Command::Error => ex
|
|
63
|
-
$stderr.puts ex.message
|
|
64
|
-
exit 1
|
|
65
|
-
|
|
66
|
-
ensure
|
|
67
|
-
super_conn&.terminate
|
|
68
|
-
conn&.terminate
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
@@ -3,111 +3,102 @@
|
|
|
3
3
|
require_relative '../builder/builder.rb'
|
|
4
4
|
|
|
5
5
|
module Prick::SubCommand
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
# An explicit :conn option is needed when running in a transaction
|
|
8
|
+
def self.run(
|
|
9
|
+
database, username, path,
|
|
10
|
+
conn: nil, seeds: true, auth: true, step: false, timer: nil, dump: nil, state: true, schema: nil)
|
|
7
11
|
|
|
8
12
|
Timer.on! if timer
|
|
9
13
|
|
|
10
14
|
Timer.time "Prick::Command#build" do
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
conn = Prick.state.connection
|
|
28
|
-
|
|
29
|
-
# Parse
|
|
30
|
-
builder = Prick::Build::Builder.new(
|
|
31
|
-
conn, path,
|
|
32
|
-
single: true, load_pool: false, seeds: seeds, auth: auth, step: step)
|
|
33
|
-
|
|
34
|
-
# Register if a build file is referenced and normalize path to
|
|
35
|
-
# include build.yml of directories
|
|
36
|
-
if File.directory?(path)
|
|
37
|
-
path = File.join(path, "build.yml")
|
|
38
|
-
is_build_file = true
|
|
39
|
-
elsif File.basename(path) == "build.yml"
|
|
40
|
-
is_build_file = true
|
|
41
|
-
else
|
|
42
|
-
is_build_file = false
|
|
43
|
-
end
|
|
15
|
+
super_conn = State.connection # Used to create new databases (doesn't make a
|
|
16
|
+
# difference right now as the database
|
|
17
|
+
# user is a superuser because we need to
|
|
18
|
+
# be able to set some superuser-only
|
|
19
|
+
# options on functions)
|
|
20
|
+
builder = nil
|
|
21
|
+
|
|
22
|
+
constrain super_conn.rdbms.exist?(database), true # FIXME Same problem as below. Also in other commands
|
|
23
|
+
|
|
24
|
+
Timer.time "Load build object" do
|
|
25
|
+
if super_conn.rdbms.exist? database # FIXME Why create database? Setup should have done this
|
|
26
|
+
exist = true
|
|
27
|
+
else
|
|
28
|
+
super_conn.rdbms.create database, owner: username
|
|
29
|
+
exist = false
|
|
30
|
+
end
|
|
44
31
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
32
|
+
conn ||= Prick.state.connection
|
|
33
|
+
|
|
34
|
+
# Parse
|
|
35
|
+
builder = Prick::Build::Builder.new(
|
|
36
|
+
conn, path,
|
|
37
|
+
single: true, load_pool: false, seeds: seeds, auth: auth, step: step)
|
|
38
|
+
|
|
39
|
+
# Register if a build file is referenced and normalize path to
|
|
40
|
+
# include build.yml of directories
|
|
41
|
+
if File.directory?(path)
|
|
42
|
+
path = File.join(path, "build.yml")
|
|
43
|
+
is_build_file = true
|
|
44
|
+
elsif File.basename(path) == "build.yml"
|
|
45
|
+
is_build_file = true
|
|
46
|
+
else
|
|
47
|
+
is_build_file = false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Read schema from build file if possible and decide if schema should
|
|
51
|
+
# be dropped beforehand
|
|
52
|
+
if is_build_file
|
|
53
|
+
if builder.root.has_schema
|
|
54
|
+
!schema or Prick.error "Can't use --schema when doing a schema build"
|
|
55
|
+
is_schema_rebuild = true
|
|
56
|
+
schema = build_node.schema
|
|
55
57
|
else
|
|
56
58
|
is_schema_rebuild = false
|
|
57
59
|
end
|
|
60
|
+
else
|
|
61
|
+
is_schema_rebuild = false
|
|
62
|
+
end
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
end
|
|
64
|
+
# Infer schema from path
|
|
65
|
+
if !schema
|
|
66
|
+
abspath = File.realpath(path)
|
|
67
|
+
schemapath = File.realpath(Prick.state.schema_dir)
|
|
68
|
+
if abspath =~ /^#{schemapath}\/([^\/]+)(?:\/.*)$/
|
|
69
|
+
schema = $1
|
|
70
|
+
else
|
|
71
|
+
Prick.error "Can't find schema" # No default schema to avoid unintended runs
|
|
68
72
|
end
|
|
73
|
+
end
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
# Write back schema to builder
|
|
76
|
+
builder.root.schema = schema
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
# Drop schema if needed
|
|
79
|
+
if is_schema_rebuild
|
|
80
|
+
conn.schema.drop schema, cascade: true
|
|
81
|
+
end
|
|
77
82
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
end
|
|
83
|
+
# Create schema if absent
|
|
84
|
+
if !conn.schema.exist?(schema)
|
|
85
|
+
conn.schema.create(schema)
|
|
82
86
|
end
|
|
87
|
+
end
|
|
83
88
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
else
|
|
91
|
-
Prick.error "Illegal dump type: #{dump.inspect}"
|
|
92
|
-
end
|
|
89
|
+
if dump
|
|
90
|
+
builder.load_pool
|
|
91
|
+
case dump
|
|
92
|
+
when :nodes; builder.nodes.reject { |node| node.is_a?(Build::BuildNode) }.map &:dump
|
|
93
|
+
when :allnodes; builder.nodes.map &:dump
|
|
94
|
+
when :batches; builder.dump
|
|
93
95
|
else
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
Prick.error "Illegal dump type: #{dump.inspect}"
|
|
97
|
+
end
|
|
98
|
+
else
|
|
99
|
+
Timer.time "Execute build object" do
|
|
100
|
+
builder.execute conn, state: state
|
|
97
101
|
end
|
|
98
|
-
|
|
99
|
-
# FIXME
|
|
100
|
-
# rescue Prick::Error => ex
|
|
101
|
-
# $stderr.puts ex.message
|
|
102
|
-
# exit 1
|
|
103
|
-
#
|
|
104
|
-
# rescue ::Command::Error => ex
|
|
105
|
-
# $stderr.puts ex.message
|
|
106
|
-
# exit 1
|
|
107
|
-
|
|
108
|
-
ensure
|
|
109
|
-
super_conn&.terminate
|
|
110
|
-
conn&.terminate
|
|
111
102
|
end
|
|
112
103
|
end
|
|
113
104
|
end
|
|
@@ -17,7 +17,7 @@ module Prick::SubCommand
|
|
|
17
17
|
Prick.state.environment = environment
|
|
18
18
|
Prick.state.save_state
|
|
19
19
|
else
|
|
20
|
-
puts Prick.state.environment
|
|
20
|
+
puts Prick.state.environment # FIXME ?
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -38,7 +38,7 @@ module Prick::SubCommand
|
|
|
38
38
|
Prick.state.environment = environment
|
|
39
39
|
Prick.state.save_state
|
|
40
40
|
else
|
|
41
|
-
puts Prick.state.database
|
|
41
|
+
puts Prick.state.database # FIXME ?
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
data/lib/prick/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: prick
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.50.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Claus Rasmussen
|
|
@@ -188,6 +188,7 @@ files:
|
|
|
188
188
|
- ".rspec"
|
|
189
189
|
- ".ruby-version"
|
|
190
190
|
- Gemfile
|
|
191
|
+
- PLAN
|
|
191
192
|
- README.md
|
|
192
193
|
- Rakefile
|
|
193
194
|
- TODO
|