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.
91 92 93 94 95 |
# File 'lib/capistrano-db-tasks/database.rb', line 91 def initialize(cap_instance) super(cap_instance) @config = YAML.load(ERB.new(File.read(File.join('config', 'database.yml'))).result)[@cap.local_rails_env.to_s] puts "local #{@config}" end |
Instance Method Details
#dump ⇒ Object
112 113 114 115 |
# File 'lib/capistrano-db-tasks/database.rb', line 112 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/
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/capistrano-db-tasks/database.rb', line 98 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.logger.info("executing local: bunzip2 -f #{file} && #{import_cmd(unzip_file)}") system("bunzip2 -f #{file} && #{import_cmd(unzip_file)}") if cleanup @cap.logger.info("removing #{unzip_file}") File.unlink(unzip_file) else @cap.logger.info("leaving #{unzip_file} (specify :db_local_clean in deploy.rb to remove)") end @cap.logger.info("Completed database import") end |
#upload ⇒ Object
117 118 119 120 |
# File 'lib/capistrano-db-tasks/database.rb', line 117 def upload remote_file = "#{@cap.current_path}/#{output_file}" @cap.upload output_file, remote_file end |