Sha256: 4cd18bf6d831a3e4e73d784ec9668cabec8f0faa91ca9907aae405a575ad227f

Contents?: true

Size: 769 Bytes

Versions: 4

Compression:

Stored size: 769 Bytes

Contents

class PgExport
  class CreateDump
    include Logging

    def initialize(dump)
      @dump = dump
    end

    def call
      validate_pg_dump_exists
      validate_db_exists(dump.database)
      execute_dump_command
      logger.info "Dump #{dump.database} to #{dump.pathname} (#{dump.size})"
    end

    private

    attr_reader :dump

    def validate_pg_dump_exists
      out = `pg_dump -V`
      /pg_dump \(PostgreSQL\)/ =~ out or raise DependencyRequiredError, 'pg_dump is required'
    end

    def validate_db_exists(database)
      PG.connect(dbname: database)
    rescue PG::ConnectionBad => e
      raise DatabaseDoesNotExistError, e.to_s
    end

    def execute_dump_command
      `pg_dump -Fc --file #{dump.pathname} #{dump.database}`
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pg_export-0.1.3 lib/pg_export/actions/create_dump.rb
pg_export-0.1.2 lib/pg_export/actions/create_dump.rb
pg_export-0.1.1 lib/pg_export/actions/create_dump.rb
pg_export-0.1.0 lib/pg_export/actions/create_dump.rb