Skip to content

Commit d9690de

Browse files
authored
Merge pull request #135 from majioa/devel
some fixes when pulling a db
2 parents b3fa9a5 + f42a8d3 commit d9690de

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/capistrano-db-tasks/database.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ def initialize(cap_instance)
108108
puts "Loading remote database config"
109109
@cap.within @cap.current_path do
110110
@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
112118
# Remove all warnings, errors and artefacts produced by bunlder, rails and other useful tools
113119
config_content = dirty_config_content.match(/#{DBCONFIG_BEGIN_FLAG}(.*?)#{DBCONFIG_END_FLAG}/m)[1]
114120
@config = YAML.load(config_content).each_with_object({}) { |(k, v), h| h[k.to_s] = v }
@@ -122,7 +128,9 @@ def dump
122128
end
123129

124130
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
126134
end
127135

128136
def clean_dump_if_needed
@@ -186,7 +194,9 @@ def dump
186194

187195
def upload
188196
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
190200
end
191201

192202
private
@@ -223,6 +233,8 @@ def remote_to_local(instance)
223233

224234
begin
225235
remote_db.dump.download
236+
rescue Exception => e
237+
puts "E[#{e.class}]: #{e.message}"
226238
ensure
227239
remote_db.clean_dump_if_needed
228240
end

0 commit comments

Comments
 (0)