Sha256: 425b674341fd5cee05550eb9063e3d048139dc0cad67c8bfa2ae55f9a4bbdc16

Contents?: true

Size: 1.16 KB

Versions: 18

Compression:

Stored size: 1.16 KB

Contents

module Dumper
  module Database
    class PostgreSQL < Base
      DUMP_TOOL = 'pg_dump'
      FILE_EXT = 'sql.gz'

      def command
        "cd #{tmpdir} && #{password_variable} #{dump_tool_path} #{connection_options} #{@config[:database]} | gzip > #{filename}"
      end

      def connection_options
        [ :host, :port, :socket, :username ].map do |option|
          next if @config[option].blank?
          "--#{option}='#{@config[option]}'".gsub('--socket', '--host')
        end.compact.join(' ')
      end

      def password_variable
        @config[:password].blank? ? '' : "PGPASSWORD='#{@config[:password]}'"
      end

      def set_config_for(rails_env=nil)
        return unless defined?(ActiveRecord::Base) &&
          ActiveRecord::Base.configurations &&
          (config = ActiveRecord::Base.configurations[rails_env]) &&
          (config['adapter'] == 'postgresql')

        @config = {
          :host => config['host'],
          :port => config['port'],
          :username => config['username'],
          :password => config['password'],
          :database => config['database'],
          :dump_tool => dump_tool_path
        }
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dumper-1.5.0 lib/dumper/database/postgresql.rb
dumper-1.4.5 lib/dumper/database/postgresql.rb
dumper-1.4.4 lib/dumper/database/postgresql.rb
dumper-1.4.3 lib/dumper/database/postgresql.rb
dumper-1.4.2 lib/dumper/database/postgresql.rb
dumper-1.4.1 lib/dumper/database/postgresql.rb
dumper-1.4.0 lib/dumper/database/postgresql.rb
dumper-1.3.7 lib/dumper/database/postgresql.rb
dumper-1.3.6 lib/dumper/database/postgresql.rb
dumper-1.3.5 lib/dumper/database/postgresql.rb
dumper-1.3.4 lib/dumper/database/postgresql.rb
dumper-1.3.3 lib/dumper/database/postgresql.rb
dumper-1.3.2 lib/dumper/database/postgresql.rb
dumper-1.3.1 lib/dumper/database/postgresql.rb
dumper-1.3.0 lib/dumper/database/postgresql.rb
dumper-1.2.1 lib/dumper/database/postgresql.rb
dumper-1.2.0 lib/dumper/database/postgresql.rb
dumper-1.1.3 lib/dumper/database/postgresql.rb