Sha256: b3f5c81e645ab6d3f341bb2f1e891a0843d0b695d01546231c2e0c4a9144286d

Contents?: true

Size: 820 Bytes

Versions: 1

Compression:

Stored size: 820 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, 'Shell command "pg_dump" is required. Pleas install "pg_dump" and try again.'
    end

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg_export-0.2.0 lib/pg_export/actions/create_dump.rb