aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
diff options
context:
space:
mode:
authorSteve Mitchell <smitchell@groupon.com>2015-09-18 14:16:15 -0500
committerSteve Mitchell <smitchell@groupon.com>2015-09-18 14:16:15 -0500
commit40664444eef2432fc564d8eecb647854bd06e5c3 (patch)
tree0860d2a6e5dab80189a791bec3e06bb404498d6a /activerecord/lib/active_record/tasks/mysql_database_tasks.rb
parent9347538312ba796ac698f06068b213ed17924e08 (diff)
downloadrails-40664444eef2432fc564d8eecb647854bd06e5c3.tar.gz
rails-40664444eef2432fc564d8eecb647854bd06e5c3.tar.bz2
rails-40664444eef2432fc564d8eecb647854bd06e5c3.zip
Check response of structure_load for mysql_database_tasks and make structure_dump consistent
Diffstat (limited to 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb')
-rw-r--r--activerecord/lib/active_record/tasks/mysql_database_tasks.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
index ba5dd0a0d9..5b07773d60 100644
--- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
@@ -56,22 +56,21 @@ module ActiveRecord
end
def structure_dump(filename)
- args = prepare_command_options('mysqldump')
+ args = prepare_command_options
args.concat(["--result-file", "#{filename}"])
args.concat(["--no-data"])
args.concat(["--routines"])
args.concat(["#{configuration['database']}"])
- unless Kernel.system(*args)
- $stderr.puts "Could not dump the database structure. "\
- "Make sure `mysqldump` is in your PATH and check the command output for warnings."
- end
+
+ run_cmd('mysqldump', args, 'dumping')
end
def structure_load(filename)
- args = prepare_command_options('mysql')
+ args = prepare_command_options
args.concat(['--execute', %{SET FOREIGN_KEY_CHECKS = 0; SOURCE #{filename}; SET FOREIGN_KEY_CHECKS = 1}])
args.concat(["--database", "#{configuration['database']}"])
- Kernel.system(*args)
+
+ run_cmd('mysql', args, 'loading')
end
private
@@ -130,7 +129,7 @@ IDENTIFIED BY '#{configuration['password']}' WITH GRANT OPTION;
$stdin.gets.strip
end
- def prepare_command_options(command)
+ def prepare_command_options
args = {
'host' => '--host',
'port' => '--port',
@@ -145,7 +144,18 @@ IDENTIFIED BY '#{configuration['password']}' WITH GRANT OPTION;
'sslkey' => '--ssl-key'
}.map { |opt, arg| "#{arg}=#{configuration[opt]}" if configuration[opt] }.compact
- [command, *args]
+ args
+ end
+
+ def run_cmd(cmd, args, action)
+ fail run_cmd_error(cmd, args, action) unless Kernel.system(cmd, *args)
+ end
+
+ def run_cmd_error(cmd, args, action)
+ msg = "failed to execute:\n"
+ msg << "#{cmd}"
+ msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
+ msg
end
end
end