11module 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
3852end
0 commit comments