lib/prick/subcommand/prick-run.rb in prick-0.34.0 vs lib/prick/subcommand/prick-run.rb in prick-0.35.0
- old
+ new
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
require_relative '../builder/builder.rb'
module Prick::SubCommand
- def self.run(database, username, path, timer: nil, dump: nil, schema: nil)
+ def self.run(database, username, path, step: false, timer: nil, dump: nil, schema: nil)
Timer.on! if timer
Timer.time "Prick::Command#build" do
begin
@@ -25,11 +25,11 @@
exist = false
end
conn = Prick.state.connection
# Parse
- builder = Prick::Build::Builder.new(conn, path, single: true)
+ builder = Prick::Build::Builder.new(conn, path, single: true, load_pool: false, step: step)
# Register if a build file is referenced and normalize path to
# include build.yml of directories
if File.directory?(path)
path = File.join(path, "build.yml")
@@ -41,13 +41,11 @@
end
# Read schema from build file if possible and decide if schema should
# be dropped beforehand
if is_build_file
- pool = builder.pool
- build_node = pool.all_nodes.first
- if build_node.has_schema
+ if builder.root.has_schema
!schema or Prick.error "Can't use --schema when doing a schema build"
is_schema_rebuild = true
schema = build_node.schema
else
is_schema_rebuild = false
@@ -65,10 +63,13 @@
else
Prick.error "Can't find schema" # No default schema to avoid unintended runs
end
end
+ # Write-back schema to builder
+ builder.root.schema = schema
+
# Drop schema if needed
if is_schema_rebuild
conn.schema.drop schema, cascade: true
end
@@ -76,29 +77,32 @@
if !conn.schema.exist?(schema)
conn.schema.create(schema)
end
end
- case dump
- when :nodes; builder.nodes.reject { |node| node.is_a?(Build::BuildNode) }.map &:dump
- when :allnodes; builder.nodes.map &:dump
- when :batches; builder.dump
- when nil;
+ if dump
+ builder.load_pool
+ case dump
+ when :nodes; builder.nodes.reject { |node| node.is_a?(Build::BuildNode) }.map &:dump
+ when :allnodes; builder.nodes.map &:dump
+ when :batches; builder.dump
+ else
+ Prick.error "Illegal dump type: #{dump.inspect}"
+ end
else
- Prick.error "Illegal dump type: #{dump.inspect}"
- end && exit
-
- Timer.time "Execute build object" do
- builder.execute conn
+ Timer.time "Execute build object" do
+ builder.execute conn
+ end
end
- rescue Prick::Error => ex
- $stderr.puts ex.message
- exit 1
-
- rescue ::Command::Error => ex
- $stderr.puts ex.message
- exit 1
+# FIXME
+# rescue Prick::Error => ex
+# $stderr.puts ex.message
+# exit 1
+#
+# rescue ::Command::Error => ex
+# $stderr.puts ex.message
+# exit 1
ensure
super_conn&.terminate
conn&.terminate
end