Sha256: 50cda461f6a098a8ff0ead9175e514c2eba1c306ad1260ef06214b098cc61313

Contents?: true

Size: 791 Bytes

Versions: 1

Compression:

Stored size: 791 Bytes

Contents

module PgDrive
  module Dump
    class << self
      def call
        stdin, stdout, stderr, wait_thr = Open3.popen3(
          pg_env,
          BACKUP_CMD,
          pgroup: true
        )

        tmpfile = Tempfile.new("pg_backup")
        tmpfile.write(stdout)
        tmpfile.rewind

        errors = stderr.read
        unless wait_thr.value.success? && errors.empty?
          raise BackupFailed, "Exit status: #{wait_thr.value.exitstatus}: #{errors}"
        end

        yield tmpfile
      ensure
        [stdin, stdout, stderr, tmpfile].compact.each(&:close)
      end

      def pg_env
        PG_ENV_MAP.map { |k, v| [k, db_conf[v].to_s] }.to_h
      end

      def db_conf
        @db_conf ||= Rails.configuration.database_configuration[Rails.env]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg_drive-0.2.0 lib/pg_drive/dump.rb