lib/capistrano/tasks/db.rake in magic_recipes_two-0.0.39 vs lib/capistrano/tasks/db.rake in magic_recipes_two-0.0.40
- old
+ new
@@ -1,8 +1,9 @@
namespace :load do
task :defaults do
- set :db_roles, -> { :db }
+ set :db_roles, -> { :db }
+ set :db_backup_on_deploy, -> { false }
end
end
namespace :db do
@@ -14,7 +15,29 @@
execute :bundle, :exec, :rake, "db:seed RAILS_ENV=#{fetch(:stage)}"
end
end
end
+ desc 'Dumb database and download yaml file'
+ task :yaml_dumb do
+ # create local backup-dir if not existing
+ run_locally do
+ execute :mkdir, "-p db/backups"
+ end
+ # download yaml version of current DB
+ on roles :db do
+ within current_path do
+ execute :bundle, :exec, :rake, "db:data:dump RAILS_ENV=#{fetch(:stage)}"
+ download! "#{current_path}/db/data.yml", "db/backups/#{ Time.now.strftime("%y-%m-%d_%H-%M") }_#{fetch(:stage)}_db_data.yml"
+ end
+ end
+ end
+
end
+namespace :deploy do
+ before :starting, :backup_database do
+ if fetch(:db_backup_on_deploy)
+ invoke "db:yaml_dumb"
+ end
+ end
+end
\ No newline at end of file