class Database::Remote

Public Class Methods

new(cap_instance) click to toggle source
Calls superclass method Database::Base::new
# File lib/capistrano-db-tasks/database.rb, line 106
def initialize(cap_instance)
  super(cap_instance)
  puts "Loading remote database config"
  @cap.within @cap.current_path do
    @cap.with rails_env: @cap.fetch(:rails_env) do
      dirty_config_content = @cap.capture(:rails, "runner \"puts '#{DBCONFIG_BEGIN_FLAG}' + ActiveRecord::Base.connection.instance_variable_get(:@config).to_yaml + '#{DBCONFIG_END_FLAG}'\"", '2>/dev/null')
      # Remove all warnings, errors and artefacts produced by bunlder, rails and other useful tools
      config_content = dirty_config_content.match(/#{DBCONFIG_BEGIN_FLAG}(.*?)#{DBCONFIG_END_FLAG}/m)[1]
      @config = YAML.load(config_content).each_with_object({}) { |(k, v), h| h[k.to_s] = v }
    end
  end
end

Public Instance Methods

clean_dump_if_needed() click to toggle source
# File lib/capistrano-db-tasks/database.rb, line 128
def clean_dump_if_needed
  if @cap.fetch(:db_remote_clean)
    @cap.execute "rm -f #{db_dump_file_path}"
  else
    puts "leaving #{db_dump_file_path} on the server (add \"set :db_remote_clean, true\" to deploy.rb to remove)"
  end
end
download(local_file = " click to toggle source
# File lib/capistrano-db-tasks/database.rb, line 124
def download(local_file = "#{output_file}")
  @cap.download! db_dump_file_path, local_file
end
dump() click to toggle source
# File lib/capistrano-db-tasks/database.rb, line 119
def dump
  @cap.execute "cd #{@cap.current_path} && #{dump_cmd} | #{compressor.compress('-', db_dump_file_path)}"
  self
end
load(file, cleanup) click to toggle source

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

# File lib/capistrano-db-tasks/database.rb, line 137
def load(file, cleanup)
  unzip_file = File.join(File.dirname(file), File.basename(file, ".#{compressor.file_extension}"))
  # @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.execute "cd #{@cap.current_path} && #{compressor.decompress(file)} && RAILS_ENV=#{@cap.fetch(:rails_env)} && #{import_cmd(unzip_file)}"
  @cap.execute("cd #{@cap.current_path} && rm #{unzip_file}") if cleanup
end

Private Instance Methods

db_dump_dir() click to toggle source
# File lib/capistrano-db-tasks/database.rb, line 150
def db_dump_dir
  @cap.fetch(:db_dump_dir) || "#{@cap.current_path}/db"
end
db_dump_file_path() click to toggle source
# File lib/capistrano-db-tasks/database.rb, line 146
def db_dump_file_path
  "#{db_dump_dir}/#{output_file}"
end