Skip to content

Add support for specifying extra command line options during database dump and load #138

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

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Reverse Chronological Order:
https://github.com/sgruhier/capistrano-db-tasks/compare/v0.6...HEAD

* Your contribution here!
* Add support for passing extra options to the database dump and load commands (@someonewithpc)
* Added support for [zstd compressor](http://facebook.github.io/zstd/) (@ocha)

# 0.6 (Dec 14 2016)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ set :disallow_pushing, true

# if you prefer bzip2/unbzip2 instead of gzip
set :compressor, :bzip2

# if you need to add extra command line options to the import or export commands
set :db_dump_extra_opts, ""
set :db_import_extra_opts, ""
```

Add to .gitignore
Expand Down
20 changes: 16 additions & 4 deletions lib/capistrano-db-tasks/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ def dump_cmd

def import_cmd(file)
if mysql?
"mysql #{credentials} -D #{database} < #{file}"
"mysql #{credentials} -D #{database} #{import_cmd_opts} < #{file}"
elsif postgresql?
terminate_connection_sql = "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '#{database}' AND pid <> pg_backend_pid();"
"#{pgpass} psql -c \"#{terminate_connection_sql};\" #{credentials} #{database}; #{pgpass} dropdb #{credentials} #{database}; #{pgpass} createdb #{credentials} #{database}; #{pgpass} psql #{credentials} -d #{database} < #{file}"
"#{pgpass} psql -c \"#{terminate_connection_sql};\" #{credentials} #{database}; #{pgpass} dropdb #{credentials} #{database}; #{pgpass} createdb #{credentials} #{database}; #{pgpass} psql #{credentials} -d #{database} #{import_cmd_opts} < #{file}"
end
end

def dump_cmd_opts
if mysql?
"--lock-tables=false #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts}"
"--lock-tables=false #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts} #{dump_cmd_extra_opts}"
elsif postgresql?
"--no-acl --no-owner #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts}"
"--no-acl --no-owner #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts} #{dump_cmd_extra_opts}"
end
end

Expand All @@ -100,6 +100,18 @@ def dump_cmd_ignore_data_tables_opts
ignore_tables = @cap.fetch(:db_ignore_data_tables, [])
ignore_tables.map { |t| "--exclude-table-data=#{t}" }.join(" ") if postgresql?
end

def dump_cmd_extra_opts
@cap.fetch(:db_dump_extra_opts, "")
end

def import_cmd_opts
import_cmd_extra_opts
end

def import_cmd_extra_opts
@cap.fetch(:db_import_extra_opts, "")
end
end

class Remote < Base
Expand Down
2 changes: 2 additions & 0 deletions lib/capistrano-db-tasks/dbtasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
set :skip_data_sync_confirm, ENV['SKIP_DATA_SYNC_CONFIRM'].to_s.casecmp('true').zero?
set :disallow_pushing, false unless fetch(:disallow_pushing)
set :compressor, :gzip unless fetch(:compressor)
set :db_dump_extra_opts, '' unless fetch(:db_dump_extra_opts)
set :db_import_extra_opts, '' unless fetch(:db_import_extra_opts)

namespace :capistrano_db_tasks do
task :check_can_push do
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano-db-tasks/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CapistranoDbTasks
VERSION = "0.6".freeze
VERSION = "0.7".freeze
end