Class: Database::Local
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(cap_instance) ⇒ Local
constructor
A new instance of Local.
-
#load(file, cleanup) ⇒ Object
cleanup = true removes the mysqldump file after loading, false leaves it in db/.
- #upload ⇒ Object
Methods inherited from Base
#credentials, #current_time, #database, #mysql?, #pgpass, #postgresql?
Constructor Details
#initialize(cap_instance) ⇒ Local
Returns a new instance of Local.
88 89 90 91 92 |
# File 'lib/capistrano-db-tasks/database.rb', line 88 def initialize(cap_instance) super(cap_instance) @config = YAML.load(ERB.new(File.read(File.join('config', 'database.yml'))).result)[fetch(:local_rails_env).to_s] puts "local #{@config}" end |
Instance Method Details
#dump ⇒ Object
109 110 111 112 |
# File 'lib/capistrano-db-tasks/database.rb', line 109 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/
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/capistrano-db-tasks/database.rb', line 95 def load(file, cleanup) unzip_file = File.join(File.dirname(file), File.basename(file, '.bz2')) # system("bunzip2 -f #{file} && bundle exec rake db:drop db:create && #{import_cmd(unzip_file)} && bundle exec rake db:migrate") @cap.info "executing local: bunzip2 -f #{file} && #{import_cmd(unzip_file)}" system("bunzip2 -f #{file} && #{import_cmd(unzip_file)}") if cleanup @cap.info "removing #{unzip_file}" File.unlink(unzip_file) else @cap.info "leaving #{unzip_file} (specify :db_local_clean in deploy.rb to remove)" end @cap.info "Completed database import" end |
#upload ⇒ Object
114 115 116 117 |
# File 'lib/capistrano-db-tasks/database.rb', line 114 def upload remote_file = "#{@cap.current_path}/#{output_file}" @cap.upload! output_file, remote_file end |