Skip to content

Commit 4058b3e

Browse files
authored
Merge pull request #89 from dtaniwaki/show-failure
Show local execution failure log
2 parents fd40e9c + 57c1b90 commit 4058b3e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/capistrano-db-tasks/database.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ def initialize(cap_instance)
152152
# cleanup = true removes the mysqldump file after loading, false leaves it in db/
153153
def load(file, cleanup)
154154
unzip_file = File.join(File.dirname(file), File.basename(file, ".#{compressor.file_extension}"))
155-
# system("bunzip2 -f #{file} && bundle exec rake db:drop db:create && #{import_cmd(unzip_file)} && bundle exec rake db:migrate")
155+
# execute("bunzip2 -f #{file} && bundle exec rake db:drop db:create && #{import_cmd(unzip_file)} && bundle exec rake db:migrate")
156156
@cap.info "executing local: #{compressor.decompress(file)}" && #{import_cmd(unzip_file)}"
157-
system("#{compressor.decompress(file)} && #{import_cmd(unzip_file)}")
157+
execute("#{compressor.decompress(file)} && #{import_cmd(unzip_file)}")
158158
if cleanup
159159
@cap.info "removing #{unzip_file}"
160160
File.unlink(unzip_file)
@@ -165,14 +165,22 @@ def load(file, cleanup)
165165
end
166166

167167
def dump
168-
system "#{dump_cmd} | #{compressor.compress('-', output_file)}"
168+
execute "#{dump_cmd} | #{compressor.compress('-', output_file)}"
169169
self
170170
end
171171

172172
def upload
173173
remote_file = "#{@cap.current_path}/#{output_file}"
174174
@cap.upload! output_file, remote_file
175175
end
176+
177+
private
178+
179+
def execute(cmd)
180+
result = system cmd
181+
@cap.error "Failed to execute the local command: #{cmd}" unless result
182+
result
183+
end
176184
end
177185

178186

0 commit comments

Comments
 (0)