lib/j-cap-recipes/tasks/database.rake in j-cap-recipes-0.0.16 vs lib/j-cap-recipes/tasks/database.rake in j-cap-recipes-0.0.17

- old
+ new

@@ -38,33 +38,38 @@ end end end end - desc 'Downlaod to local machine the latest backup' - task :dump_download do + desc 'Download to local machine the latest backup' + task :dump_download, :env_name do |task, args| on primary fetch(:migration_role) do within release_path do FileUtils.mkdir_p 'db/backups' - bakup_file = "db/backups/#{fetch(:application)}_#{fetch(:rails_env).to_s}_latest.dump" - download! "#{release_path}/#{bakup_file}", bakup_file + env_name = args[:env_name] || fetch(:rails_env).to_s + database_config_content = read_remote_database_config + database_name = JCap::Recipes::Util.database_name(env_name, database_config_content) + backup_file = "db/backups/#{database_name}_latest.dump" + download! "#{release_path}/#{backup_file}", backup_file end end end - desc 'Downlaod to local machine the latest backup' - task :dump_upload do + desc 'Download to local machine the latest backup' + task :dump_upload, :env_name do |task, args| on primary fetch(:migration_role) do within release_path do FileUtils.mkdir_p 'db/backups' - bakup_file = "db/backups/#{fetch(:application)}_#{fetch(:rails_env).to_s}_latest.dump" - upload! bakup_file, "#{release_path}/#{bakup_file}" + env_name = args[:env_name] || fetch(:rails_env).to_s + database_config_content = read_remote_database_config + database_name = JCap::Recipes::Util.database_name(env_name, database_config_content) + backup_file = "db/backups/#{database_name}_latest.dump" + upload! backup_file, "#{release_path}/#{backup_file}" end end end - end remote_file 'config/database.yml' => '/tmp/database.yml', roles: :app after 'config/database.yml', :remove_db_tmp_file do File.delete '/tmp/database.yml' @@ -91,6 +96,10 @@ config = ERB.new(template) File.open t.name, 'w' do |f| f.puts config.result(binding) end +end + +def read_remote_database_config(path = 'config/database.yml') + capture :cat, path end