diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-09-22 10:49:49 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-09-22 11:10:58 +0200 |
commit | 3931cec9cd3091ef4b8ee40066b896385d2085ea (patch) | |
tree | b0b5f3a5992201577465d350e1cd4507ede41339 /activerecord/lib/active_record/tasks | |
parent | 8842ce239562d3fbc82198ac3c4618935134ff39 (diff) | |
parent | 40664444eef2432fc564d8eecb647854bd06e5c3 (diff) | |
download | rails-3931cec9cd3091ef4b8ee40066b896385d2085ea.tar.gz rails-3931cec9cd3091ef4b8ee40066b896385d2085ea.tar.bz2 rails-3931cec9cd3091ef4b8ee40066b896385d2085ea.zip |
Merge pull request #20569 from theSteveMitchell/master
Check mysql structure_load for errors
Diffstat (limited to 'activerecord/lib/active_record/tasks')
-rw-r--r-- | activerecord/lib/active_record/tasks/mysql_database_tasks.rb | 27 |
1 files changed, 18 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..8929aa85c8 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,17 @@ 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: `#{cmd}`\n" + 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 |