def psql_file(filename, path)
      Preconditions.assert_class(path, String)
      Preconditions.check_state(File.exists?(path), "File[%s] not found" % path)

      options = Db.attribute_values(path).join(" ")

      Library.with_temp_file(:prefix => File.basename(path)) do |tmp|
        File.open(tmp, "w") do |out|
          out << "\\set ON_ERROR_STOP true\n\n"
          out << IO.read(path)
        end

        command = "psql --file \"%s\" #{options} %s" % [tmp, @url]

        Library.with_temp_file do |output|
          result = `#{command} > #{output} 2>&1`.strip
          status = $?
          if status.to_i > 0
            errors = File.exists?(output) ? IO.read(output) : result
            raise ScriptError.new(self, filename, path, errors)
          end
        end
      end
    end
def psql_file(filename, path)
      Preconditions.assert_class(path, String)
      Preconditions.check_state(File.exists?(path), "File[%s] not found" % path)

      options = Db.attribute_values(path).join(" ")

      Library.with_temp_file(:prefix => File.basename(path)) do |tmp|
        File.open(tmp, "w") do |out|
          out << "\\set ON_ERROR_STOP true\n\n"
          out << IO.read(path)
        end

        command = "psql --file \"%s\" #{options} %s" % [tmp, @url]

        Library.with_temp_file do |output|
          result = `#{command} > #{output} 2>&1`.strip
          status = $?
          if status.to_i > 0
            errors = File.exists?(output) ? IO.read(output) : result
            raise ScriptError.new(self, filename, path, errors)
          end
        end
      end
    end
executes sql commands from a file in a single transaction