Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#61 - allow directory for db file to be an option #62

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best way to have named prefix. For example

set :db_prefix, -> { fetch(:stage) }


# 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: 15 additions & 3 deletions lib/capistrano-db-tasks/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,32 @@ 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

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

Expand Down