Class: Dumper::Database::PostgreSQL

Inherits:
Base
  • Object
show all
Defined in:
lib/dumper/database/postgresql.rb

Constant Summary collapse

DUMP_TOOL =
'pg_dump'
FORMAT =
'sql'

Instance Attribute Summary

Attributes inherited from Base

#config, #custom_options, #filename, #format, #tmpdir

Instance Method Summary collapse

Methods inherited from Base

#dump_path, #dump_tool_path, #file_ext, #finalize

Methods included from Utility::ObjectFinder

#find_instance_in_object_space

Instance Method Details

#commandObject



7
8
9
# File 'lib/dumper/database/postgresql.rb', line 7

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

#connection_optionsObject



11
12
13
14
15
16
# File 'lib/dumper/database/postgresql.rb', line 11

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

#password_variableObject



18
19
20
# File 'lib/dumper/database/postgresql.rb', line 18

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

#set_config_for(rails_env = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dumper/database/postgresql.rb', line 22

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