lib/subcommand/prick-build.rb in prick-0.20.15 vs lib/subcommand/prick-build.rb in prick-0.20.16

- old
+ new

@@ -5,44 +5,48 @@ module Prick::SubCommand def self.build(database, username, schema, builddir: "schema", force: false, timer: nil, dump: nil) Timer.on! if timer time "Prick::Command#build" do begin - super_conn = PgConn.new + super_conn = PgConn.new # Used to create new databases (doesn't make a + # difference right now as the mikras user is + # still a superuser) conn = nil builder = nil time "Load build object" do if super_conn.rdbms.exist? database conn = PgConn.new(database, username) exist = true else super_conn.rdbms.create database, owner: username conn = PgConn.new(database, username) - exit = false + exist = false end builder = Prick::Build::Builder.new(conn, builddir) if exist if force - builder.schemas.each { |schema| conn.schema.drop schema, cascade: true } + # Drop all schemas + super_conn.rdbms.empty!(database) else - # Explicit schema is always rebuilt - refresh = [builder.refresh_schemas, schema].compact.flatten.uniq - keep = builder.keep_schemas.reject { |s| s == schema } + # Find schemas to refresh. This includes all schemas in the + # database + refresh_schemas = conn.schema.list - # Rebuild non-existing keep-schemas - keep.reject! { |schema| - refresh << schema if !conn.schema.exist?(schema) - } + # Find existing keep-schemas + keep_schemas = builder.keep_schemas.select { |s| conn.schema.exist?(s) } + # Remove keep-schemas from list of schemas + refresh_schemas -= keep_schemas + # Eliminate keep schemas from build pool - builder.pool.delete_schema(keep) + builder.pool.delete_schema(keep_schemas) # Drop refresh schemes - refresh.each { |schema| conn.schema.drop(schema, cascade: true) } + refresh_schemas.each { |schema| conn.schema.drop(schema, cascade: true) } end end # Delete schemas after target scheme if present builder.pool.delete_schema(builder.pool.after_schema(schema)) if schema