Class: Dumper::Database::MySQL

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

Constant Summary collapse

DUMP_TOOL =
'mysqldump'
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

#additional_optionsObject



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

def additional_options
  '--single-transaction'
end

#commandObject



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

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

#connection_optionsObject



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

def connection_options
  [ :host, :port, :username, :password ].map do |option|
    next if @config[option].blank?
    "--#{option}='#{@config[option]}'".gsub('--username', '--user')
  end.compact.join(' ')
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/mysql.rb', line 22

def set_config_for(rails_env=nil)
  return unless defined?(ActiveRecord::Base) &&
    ActiveRecord::Base.configurations &&
    (config = ActiveRecord::Base.configurations[rails_env]) &&
    %w(mysql mysql2 mysql2spatial).include?(config['adapter'])

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