Skip to content

Commit f36ab98

Browse files
committed
Add support for specifying extra command line options during database dump and load
1 parent d9690de commit f36ab98

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Reverse Chronological Order:
77
https://github.com/sgruhier/capistrano-db-tasks/compare/v0.6...HEAD
88

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

1213
# 0.6 (Dec 14 2016)

lib/capistrano-db-tasks/database.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ def dump_cmd
7272

7373
def import_cmd(file)
7474
if mysql?
75-
"mysql #{credentials} -D #{database} < #{file}"
75+
"mysql #{credentials} -D #{database} #{import_cmd_opts} < #{file}"
7676
elsif postgresql?
7777
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();"
78-
"#{pgpass} psql -c \"#{terminate_connection_sql};\" #{credentials} #{database}; #{pgpass} dropdb #{credentials} #{database}; #{pgpass} createdb #{credentials} #{database}; #{pgpass} psql #{credentials} -d #{database} < #{file}"
78+
"#{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}"
7979
end
8080
end
8181

8282
def dump_cmd_opts
8383
if mysql?
84-
"--lock-tables=false #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts}"
84+
"--lock-tables=false #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts} #{dump_cmd_extra_opts}"
8585
elsif postgresql?
86-
"--no-acl --no-owner #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts}"
86+
"--no-acl --no-owner #{dump_cmd_ignore_tables_opts} #{dump_cmd_ignore_data_tables_opts} #{dump_cmd_extra_opts}"
8787
end
8888
end
8989

@@ -100,6 +100,18 @@ def dump_cmd_ignore_data_tables_opts
100100
ignore_tables = @cap.fetch(:db_ignore_data_tables, [])
101101
ignore_tables.map { |t| "--exclude-table-data=#{t}" }.join(" ") if postgresql?
102102
end
103+
104+
def dump_cmd_extra_opts
105+
@cap.fetch(:db_dump_extra_opts, "")
106+
end
107+
108+
def import_cmd_opts
109+
import_cmd_extra_opts
110+
end
111+
112+
def import_cmd_extra_opts
113+
@cap.fetch(:db_import_extra_opts, "")
114+
end
103115
end
104116

105117
class Remote < Base

lib/capistrano-db-tasks/dbtasks.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
set :skip_data_sync_confirm, ENV['SKIP_DATA_SYNC_CONFIRM'].to_s.casecmp('true').zero?
1515
set :disallow_pushing, false unless fetch(:disallow_pushing)
1616
set :compressor, :gzip unless fetch(:compressor)
17+
set :db_dump_extra_opts, '' unless fetch(:db_dump_extra_opts)
18+
set :db_import_extra_opts, '' unless fetch(:db_import_extra_opts)
1719

1820
namespace :capistrano_db_tasks do
1921
task :check_can_push do

0 commit comments

Comments
 (0)