Class: Database::Remote

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

Instance Attribute Summary

Attributes inherited from Base

#config, #output_file

Instance Method Summary collapse

Methods inherited from Base

#credentials, #database, #mysql?

Constructor Details

#initialize(cap_instance) ⇒ Remote

Returns a new instance of Remote.



35
36
37
38
# File 'lib/mysql.rb', line 35

def initialize(cap_instance)
  super(cap_instance)
  @cap.run("cat #{@cap.current_path}/config/database.yml") { |c, s, d| @config = YAML.load(d)[(@cap.rails_env || 'production').to_s] }
end

Instance Method Details

#download(local_file = "#{output_file}") ⇒ Object



45
46
47
48
# File 'lib/mysql.rb', line 45

def download(local_file = "#{output_file}")
  remote_file = "#{@cap.current_path}/#{output_file}"
  @cap.get remote_file, local_file
end

#dumpObject



40
41
42
43
# File 'lib/mysql.rb', line 40

def dump
  @cap.run "cd #{@cap.current_path}; #{dump_cmd} | bzip2 - - > #{output_file}"
  self
end

#load(file, cleanup) ⇒ Object

cleanup = true removes the mysqldump file after loading, false leaves it in db/



51
52
53
54
55
# File 'lib/mysql.rb', line 51

def load(file, cleanup)
  unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
  @cap.run "cd #{@cap.current_path}; bunzip2 -f #{file} && RAILS_ENV=#{@cap.rails_env} #{rake} db:drop db:create && #{import_cmd(unzip_file)}"
  File.unlink(unzip_file) if cleanup
end