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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78522ab44a921e407fe85e69b54adb1ee7eedf7b100eb1a55dc216838a89900f
4
- data.tar.gz: 753d69e339b607c2e97695aa6364d19b019af7725bf2f4c190b067003c933fd4
3
+ metadata.gz: 7c804f1ec2c646b27750010611bac31acad4eb530500c6f77d8044b5cb703973
4
+ data.tar.gz: eca5f60a7af6a5e455e97541c69b373e466a9d7c7b72347d891ede3758631272
5
5
  SHA512:
6
- metadata.gz: 88ed1e7b0e9d0b4a7ea7f609ce706101467ea0879e057906e9ac07edceb6e863061ced5e0cfbd7c58f07c207317b01c237ae7c6fd6795b433ee16af853764295
7
- data.tar.gz: 2b95d9d37502e2b423e090a2af6d7070aab77e1689b751af736aa628c6570fe91ef19b75544c449cae777c8c4504c3d7fbab863f9d3c6907a75d4f540dd172a9
6
+ metadata.gz: 7b5d8d62790b80d92ce16ce3a55348c5475de293aa0fec503a60668d583693c1a9c2218fdfb4f90d0be62b14ee2cc8011fa73fb29c870b03fb3374c7a50b4b57
7
+ data.tar.gz: aab1dc22c44a1ba6bfe66f851e307b5a0c729702c9177cdfab1a91686afccb1a5e6337c6d8e3de6ab7b08ddd43cde46e243cc4f43cadf8cec3e7b9d329888032
data/PLAN ADDED
@@ -0,0 +1,9 @@
1
+
2
+ Prick should be split up in sub-tools
3
+
4
+ * build process
5
+ * database administration
6
+ * user administration
7
+ * backup/restore
8
+ * release tool
9
+ * fox tool
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
- Create the prick schema. The database and owner are created if needed
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
- clean_pg_meta_cache
418
- database, username, environment = parse_database_args(state, args)
419
- if Prick::SubCommand.exist_database?(database)
420
- Prick::SubCommand.clean(database, exclude: [])
421
- Prick::SubCommand.init_database(database, username, environment)
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
@@ -33,7 +33,7 @@ module Prick
33
33
 
34
34
  class SqlBatch < BuildBatch
35
35
  def execute
36
- # puts "#execute"
36
+ # puts "#execute #{nodes.inspect}"
37
37
  super {
38
38
  file = nil
39
39
  node = nil
@@ -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::init_database(database, username)
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
- init_database database, username, environment
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.init_database(database, username, environment)
30
- # Setup Prick schema. Note that this is hardcoded, the prick build file
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
- PRICK_BUILD_FILES.each { |file| conn.exec(IO.read("#{SCHEMA_PRICK_DIR}/#{file}")) }
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: nil,
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
- def self.run(database, username, path, seeds: true, auth: true, step: false, timer: nil, dump: nil, schema: nil)
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
- begin
12
- super_conn = State.connection # Used to create new databases (doesn't make a
13
- # difference right now as the database user is
14
- # a superuser anyway
15
- conn = nil
16
- builder = nil
17
-
18
- constrain super_conn.rdbms.exist?(database), true # FIXME Same problem as below. Also in other commands
19
-
20
- Timer.time "Load build object" do
21
- if super_conn.rdbms.exist? database # FIXME Why create database? Setup should have done this
22
- exist = true
23
- else
24
- super_conn.rdbms.create database, owner: username
25
- exist = false
26
- end
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
- # Read schema from build file if possible and decide if schema should
46
- # be dropped beforehand
47
- if is_build_file
48
- if builder.root.has_schema
49
- !schema or Prick.error "Can't use --schema when doing a schema build"
50
- is_schema_rebuild = true
51
- schema = build_node.schema
52
- else
53
- is_schema_rebuild = false
54
- end
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
- # Infer schema from path
60
- if !schema
61
- abspath = File.realpath(path)
62
- schemapath = File.realpath(Prick.state.schema_dir)
63
- if abspath =~ /^#{schemapath}\/([^\/]+)(?:\/.*)$/
64
- schema = $1
65
- else
66
- Prick.error "Can't find schema" # No default schema to avoid unintended runs
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
- # Write back schema to builder
71
- builder.root.schema = schema
75
+ # Write back schema to builder
76
+ builder.root.schema = schema
72
77
 
73
- # Drop schema if needed
74
- if is_schema_rebuild
75
- conn.schema.drop schema, cascade: true
76
- end
78
+ # Drop schema if needed
79
+ if is_schema_rebuild
80
+ conn.schema.drop schema, cascade: true
81
+ end
77
82
 
78
- # Create schema if absent
79
- if !conn.schema.exist?(schema)
80
- conn.schema.create(schema)
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
- if dump
85
- builder.load_pool
86
- case dump
87
- when :nodes; builder.nodes.reject { |node| node.is_a?(Build::BuildNode) }.map &:dump
88
- when :allnodes; builder.nodes.map &:dump
89
- when :batches; builder.dump
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
- Timer.time "Execute build object" do
95
- builder.execute conn
96
- end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prick
4
- VERSION = "0.49.0"
4
+ VERSION = "0.50.0"
5
5
  end
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.49.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