Skip to content

Commit dee4409

Browse files
committed
use new args
1 parent 3a41c80 commit dee4409

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

lib/db/dump_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
module DumpHelper
44
def self.dump_on_local()
5-
args = Helper::mysql_args(['--no-create-db'])
5+
args = Helper::mysql_dump_args
66

77
run_locally do
88
execute "mysqldump #{args} > #{fetch(:db_local_dump)}"
99
end
1010
end
1111

1212
def self.dump_on_server_and_download()
13-
args = Helper::mysql_args(['--no-create-db'])
13+
args = Helper::mysql_dump_args
1414

1515
execute "mysqldump #{args} > #{fetch(:db_remote_dump)}"
1616

1717
download!(fetch(:db_remote_dump), fetch(:db_local_dump))
1818
end
1919

2020
def self.dump_on_container_and_download(container)
21-
args = Helper::mysql_args(['--no-create-db'])
21+
args = Helper::mysql_dump_args
2222

2323
container.execute("mysqldump #{args} > #{fetch(:db_remote_dump)}")
2424

lib/db/helper.rb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
module Helper
2-
def self.mysql_args(additional_args=[])
3-
command = " -u #{fetch(:db_user)}"
4-
command+= " -p#{fetch(:db_pass)}" unless fetch(:db_pass).empty?
5-
command+= " #{additional_args.join(' ')} "
2+
def self.mysql_dump_args
3+
command = mysql_auth_args
4+
command+= " #{fetch(:db_additional_dump_args).join(' ')} "
5+
command+= " #{fetch(:db_name)}" unless fetch(:db_name).empty?
6+
command
7+
end
68

7-
# dont use --database statement, so no use '...' will be generated
9+
def self.mysql_restore_args
10+
command = mysql_auth_args
11+
command+= " #{fetch(:db_additional_restore_args).join(' ')} "
812
command+= " #{fetch(:db_name)}" unless fetch(:db_name).empty?
913
command
1014
end
1115

16+
def self.mysql_auth_args
17+
command = " -u #{fetch(:db_user)}"
18+
command+= " -p#{fetch(:db_pass)}" unless fetch(:db_pass).empty?
19+
command+= " #{fetch(:db_additional_auth_args).join(' ')} "
20+
command
21+
end
22+
1223
def self.append_stage_to_filename(file_name, stage = 'local')
1324
splitted = file_name.split('.')
1425
extension = splitted.pop
@@ -26,13 +37,16 @@ def self.local_stage?
2637
fetch(:local_stage_name).to_sym == fetch(:stage).to_sym
2738
end
2839

29-
def execute_local_or_remote(cmd)
30-
if local_stage?
31-
run_locally do
32-
execute cmd
40+
def self.execute_db_command_autodetect(cmd)
41+
cmd = "mysql #{Helper::mysql_auth_args} -e \"#{cmd}\""
42+
43+
if fetch(:db_is_container)
44+
db_container = container_by_name fetch(:db_container_name)
45+
on_container db_container do |container|
46+
container.execute cmd
3347
end
3448
else
35-
execute cmd
49+
execute_local_or_remote cmd
3650
end
3751
end
3852
end

lib/db/load_helper.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
require_relative "helper.rb"
2+
require 'capistrano/container'
23

34
module LoadHelper
45
def self.import_on_local()
56
run_locally do
6-
execute "mysql #{Helper::mysql_args} < #{fetch(:db_local_dump)}"
7+
execute "mysql #{Helper::mysql_restore_args} < #{fetch(:db_local_dump)}"
78
end
89
end
910

1011
def self.import_on_container(container)
1112
container.upload!(fetch(:db_local_dump), fetch(:db_remote_dump))
1213

13-
container.execute("mysql #{Helper::mysql_args} < #{fetch(:db_remote_dump)}")
14+
container.execute "mysql #{Helper::mysql_restore_args} < #{fetch(:db_remote_dump)}"
1415
end
1516

1617
def self.import_on_server()
1718
upload!(fetch(:db_local_dump), fetch(:db_remote_dump))
1819

19-
execute("mysql #{Helper::mysql_args} < #{fetch(:db_remote_dump)}")
20+
execute("mysql #{Helper::mysql_restore_args} < #{fetch(:db_remote_dump)}")
2021
end
2122
end

0 commit comments

Comments
 (0)