Sha256: 092048aca19fe6f544951750d48380cd8989c18e5557f1c1ff517136285d0e17

Contents?: true

Size: 787 Bytes

Versions: 13

Compression:

Stored size: 787 Bytes

Contents

# frozen_string_literal: true

require 'open3'

class PgExport
  module Adapters
    class BashAdapter
      class PgRestoreError < StandardError; end
      class PgDumpError < StandardError; end

      def pg_dump(file, db_name)
        popen("pg_dump -Fc --file #{file.path} #{db_name}") do |errors|
          raise PgDumpError, errors.chomp unless errors.empty?
        end

        file
      end

      def pg_restore(file, db_name)
        popen("pg_restore -c -d #{db_name} #{file.path}") do |errors|
          raise PgRestoreError, errors.chomp if /FATAL/ =~ errors
        end
      end

      private

      def popen(command)
        Open3.popen3(command) do |_, _, err|
          errors = err.read
          yield errors
        end

        self
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pg_export-1.0.0.rc5 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-1.0.0.rc4 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-1.0.0.rc3 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-1.0.0.rc2 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-1.0.0.rc1 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-0.7.7 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-0.7.6 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-0.7.5 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-0.7.4 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-0.7.3 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-0.7.2 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-0.7.1 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
pg_export-0.7.0 lib/pg_export/lib/pg_export/adapters/bash_adapter.rb