Skip to content

Commit

Permalink
Merge pull request #101 from artempartos/feature/configurable_dump_fo…
Browse files Browse the repository at this point in the history
…lder

Feature/configurable dump folder
  • Loading branch information
numbata committed Nov 30, 2016
2 parents 4bda81b + deca536 commit 5da3617
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ set :db_ignore_tables, []
# if you want to exclude table data (but not table schema) from dump
set :db_ignore_data_tables, []

# configure location where the dump file should be created
set :db_dump_dir, "./db"

# 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)
Expand Down
18 changes: 11 additions & 7 deletions lib/capistrano-db-tasks/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def current_time
end

def output_file
@output_file ||= "db/#{database}_#{current_time}.sql.#{compressor.file_extension}"
@output_file ||= "#{database}_#{current_time}.sql.#{compressor.file_extension}"
end

def compressor
Expand Down Expand Up @@ -117,19 +117,19 @@ def initialize(cap_instance)
end

def dump
@cap.execute "cd #{@cap.current_path} && #{dump_cmd} | #{compressor.compress('-', output_file)}"
@cap.execute "cd #{@cap.current_path} && #{dump_cmd} | #{compressor.compress('-', db_dump_file_path)}"
self
end

def download(local_file = "#{output_file}")
@cap.download! dump_file_path, local_file
@cap.download! db_dump_file_path, local_file
end

def clean_dump_if_needed
if @cap.fetch(:db_remote_clean)
@cap.execute "rm -f #{dump_file_path}"
@cap.execute "rm -f #{db_dump_file_path}"
else
@cap.info "leaving #{dump_file_path} on the server (add \"set :db_remote_clean, true\" to deploy.rb to remove)"
@cap.info "leaving #{db_dump_file_path} on the server (add \"set :db_remote_clean, true\" to deploy.rb to remove)"
end
end

Expand All @@ -143,8 +143,12 @@ def load(file, cleanup)

private

def dump_file_path
"#{@cap.current_path}/#{output_file}"
def db_dump_file_path
"#{db_dump_dir}/#{output_file}"
end

def db_dump_dir
@cap.fetch(:db_dump_dir) || "#{@cap.current_path}/db"
end
end

Expand Down

0 comments on commit 5da3617

Please sign in to comment.