Class: Database::Local

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) ⇒ Local

Returns a new instance of Local.



59
60
61
62
# File 'lib/mysql.rb', line 59

def initialize(cap_instance)
  super(cap_instance)
  @config = YAML.load_file(File.join('config', 'database.yml'))[@cap.local_rails_env]
end

Instance Method Details

#dumpObject



71
72
73
74
# File 'lib/mysql.rb', line 71

def dump
  system "#{dump_cmd} | bzip2 - - > #{output_file}"
  self
end

#load(file, cleanup) ⇒ Object

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



65
66
67
68
69
# File 'lib/mysql.rb', line 65

def load(file, cleanup)
  unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2'))
  system("bunzip2 -f #{file} && #{rake} db:drop db:create && #{import_cmd(unzip_file)} && #{rake} db:migrate")
  File.unlink(unzip_file) if cleanup
end

#uploadObject



76
77
78
79
# File 'lib/mysql.rb', line 76

def upload
  remote_file = "#{@cap.current_path}/#{output_file}"
  @cap.upload output_file, remote_file
end