From b362a4900f7235ecffb486bb3638c72178f9738d Mon Sep 17 00:00:00 2001 From: Peter Philips Date: Thu, 14 May 2015 14:46:53 -0700 Subject: [PATCH 1/4] #61 - allow directory for db file to be an option --- lib/capistrano-db-tasks/database.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/capistrano-db-tasks/database.rb b/lib/capistrano-db-tasks/database.rb index 29f8b87..9e4d948 100644 --- a/lib/capistrano-db-tasks/database.rb +++ b/lib/capistrano-db-tasks/database.rb @@ -41,13 +41,21 @@ def current_time end def output_file - @output_file ||= "db/#{database}_#{current_time}.sql.bz2" + @output_file ||= "#{local_db_dir}/#{prefix_db_with_stage}#{database}_#{current_time}.sql.bz2" end def pgpass "PGPASSWORD='#{@config['password']}'" if @config['password'] end + def local_db_dir + @local_db_dir ||= @cap.fetch(:local_db_dir) || "db" + end + + def prefix_db_with_stage + @db_prefix ||= @cap.fetch(:prefix_db_with_stage) ? "#{@cap.fetch(:stage)}" : "" + end + private def dump_cmd From 3aa9f372f93b81af463fee11f2dd01c7862c945f Mon Sep 17 00:00:00 2001 From: Peter Philips Date: Thu, 14 May 2015 14:49:13 -0700 Subject: [PATCH 2/4] add underscore to stage prefix --- lib/capistrano-db-tasks/database.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano-db-tasks/database.rb b/lib/capistrano-db-tasks/database.rb index 9e4d948..b29d2f9 100644 --- a/lib/capistrano-db-tasks/database.rb +++ b/lib/capistrano-db-tasks/database.rb @@ -53,7 +53,7 @@ def local_db_dir end def prefix_db_with_stage - @db_prefix ||= @cap.fetch(:prefix_db_with_stage) ? "#{@cap.fetch(:stage)}" : "" + @db_prefix ||= @cap.fetch(:prefix_db_with_stage) ? "#{@cap.fetch(:stage)}_" : "" end private From 6be2294e6396ea59f61f9a394ca9b84321ce877e Mon Sep 17 00:00:00 2001 From: Peter Philips Date: Thu, 14 May 2015 14:50:52 -0700 Subject: [PATCH 3/4] update documentation --- README.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.markdown b/README.markdown index a68a389..5a08e02 100644 --- a/README.markdown +++ b/README.markdown @@ -36,6 +36,10 @@ Add to config/deploy.rb: # if you want to remove the dump file from the server after downloading set :db_remote_clean, true + # configure the local db filename + set :local_db_dir, "tmp" + set :prefix_db_with_stage, true #staging_appname_prod_20150501011.sql.bz2 + # If you want to import assets, you can change default asset dir (default = system) # This directory must be in your shared directory on the server set :assets_dir, %w(public/assets public/att) From 8862ae309eb5262174ee8c33e764cd8ccbb8931b Mon Sep 17 00:00:00 2001 From: Peter Philips Date: Wed, 20 May 2015 22:12:53 -0700 Subject: [PATCH 4/4] add ability to add flags to dump cmd --- lib/capistrano-db-tasks/database.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/capistrano-db-tasks/database.rb b/lib/capistrano-db-tasks/database.rb index b29d2f9..87c9468 100644 --- a/lib/capistrano-db-tasks/database.rb +++ b/lib/capistrano-db-tasks/database.rb @@ -56,13 +56,17 @@ def prefix_db_with_stage @db_prefix ||= @cap.fetch(:prefix_db_with_stage) ? "#{@cap.fetch(:stage)}_" : "" end + def dump_cmd_flags + @dump_cmd_flags ||= @cap.fetch(:dump_cmd_flags) || '' + end + private def dump_cmd if mysql? - "mysqldump #{credentials} #{database} --lock-tables=false" + "mysqldump #{dump_cmd_flags} #{credentials} #{database} --lock-tables=false" elsif postgresql? - "#{pgpass} pg_dump --no-acl --no-owner #{credentials} #{database}" + "#{pgpass} pg_dump #{dump_cmd_flags} --no-acl --no-owner #{credentials} #{database}" end end