Skip to content

Commit

Permalink
Add support for specifying extra command line options during database…
Browse files Browse the repository at this point in the history
… dump and load
  • Loading branch information
someonewithpc committed Dec 20, 2023
1 parent d9690de commit f36ab98
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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
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

0 comments on commit f36ab98

Please sign in to comment.