Class: Database::Remote
- Defined in:
- lib/capistrano-db-tasks/database.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #download(local_file = "#{output_file}") ⇒ Object
- #dump ⇒ Object
-
#initialize(cap_instance) ⇒ Remote
constructor
A new instance of Remote.
-
#load(file, cleanup) ⇒ Object
cleanup = true removes the mysqldump file after loading, false leaves it in db/.
Methods inherited from Base
#credentials, #current_time, #database, #mysql?, #pgpass, #postgresql?
Constructor Details
#initialize(cap_instance) ⇒ Remote
Returns a new instance of Remote.
62 63 64 65 66 67 68 69 |
# File 'lib/capistrano-db-tasks/database.rb', line 62 def initialize(cap_instance) super(cap_instance) @config = "" @cap.run("cat #{@cap.current_path}/config/database.yml") do |c, s, d| @config += d end @config = YAML.load(ERB.new(@config).result)[@cap.rails_env.to_s] end |
Instance Method Details
#download(local_file = "#{output_file}") ⇒ Object
76 77 78 79 |
# File 'lib/capistrano-db-tasks/database.rb', line 76 def download(local_file = "#{output_file}") remote_file = "#{@cap.current_path}/#{output_file}" @cap.get remote_file, local_file end |
#dump ⇒ Object
71 72 73 74 |
# File 'lib/capistrano-db-tasks/database.rb', line 71 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/
82 83 84 85 86 87 |
# File 'lib/capistrano-db-tasks/database.rb', line 82 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} bundle exec rake db:drop db:create && #{import_cmd(unzip_file)}" @cap.run "cd #{@cap.current_path} && bunzip2 -f #{file} && RAILS_ENV=#{@cap.rails_env} && #{import_cmd(unzip_file)}" @cap.run("cd #{@cap.current_path} && rm #{unzip_file}") if cleanup end |