@@ -108,7 +108,13 @@ def initialize(cap_instance)
108
108
puts "Loading remote database config"
109
109
@cap . within @cap . current_path do
110
110
@cap . with rails_env : @cap . fetch ( :rails_env ) do
111
- dirty_config_content = @cap . capture ( :rails , "runner \" puts '#{ DBCONFIG_BEGIN_FLAG } ' + Rails.application.config.database_configuration[Rails.env].to_yaml + '#{ DBCONFIG_END_FLAG } '\" " , '2>/dev/null' )
111
+ run_string = "runner \" puts '#{ DBCONFIG_BEGIN_FLAG } ' + ActiveRecord::Base.connection.instance_variable_get(:@config).to_yaml + '#{ DBCONFIG_END_FLAG } '\" "
112
+ dirty_config_content =
113
+ if @cap . capture ( :ruby , "bin/rails -v" , '2>/dev/null' ) . size > 0
114
+ @cap . capture ( :ruby , "bin/rails #{ run_string } " , '2>/dev/null' )
115
+ else
116
+ @cap . capture ( :rails , run_string , '2>/dev/null' )
117
+ end
112
118
# Remove all warnings, errors and artefacts produced by bunlder, rails and other useful tools
113
119
config_content = dirty_config_content . match ( /#{ DBCONFIG_BEGIN_FLAG } (.*?)#{ DBCONFIG_END_FLAG } /m ) [ 1 ]
114
120
@config = YAML . load ( config_content ) . each_with_object ( { } ) { |( k , v ) , h | h [ k . to_s ] = v }
@@ -122,7 +128,9 @@ def dump
122
128
end
123
129
124
130
def download ( local_file = "#{ output_file } " )
125
- @cap . download! db_dump_file_path , local_file
131
+ @cap . within @cap . current_path do
132
+ @cap . download! db_dump_file_path , local_file
133
+ end
126
134
end
127
135
128
136
def clean_dump_if_needed
@@ -186,7 +194,9 @@ def dump
186
194
187
195
def upload
188
196
remote_file = "#{ @cap . current_path } /#{ output_file } "
189
- @cap . upload! output_file , remote_file
197
+ @cap . within @cap . current_path do
198
+ @cap . upload! output_file , remote_file
199
+ end
190
200
end
191
201
192
202
private
@@ -223,6 +233,8 @@ def remote_to_local(instance)
223
233
224
234
begin
225
235
remote_db . dump . download
236
+ rescue Exception => e
237
+ puts "E[#{ e . class } ]: #{ e . message } "
226
238
ensure
227
239
remote_db . clean_dump_if_needed
228
240
end
0 commit comments