diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-01-15 09:20:43 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-01-15 09:20:44 -0200 |
commit | e709134214571d27cf2872a38c998a0e7bbc71f8 (patch) | |
tree | f36ebb7f5eb9df32a93b70de7d3e7e5c1814b34b | |
parent | 5d06f8a0a543bab761a72bb9a16cfedf3ae13f04 (diff) | |
download | rails-e709134214571d27cf2872a38c998a0e7bbc71f8.tar.gz rails-e709134214571d27cf2872a38c998a0e7bbc71f8.tar.bz2 rails-e709134214571d27cf2872a38c998a0e7bbc71f8.zip |
Improve mysql database tasks handling to ensure we always rescue from an exception
We were previously rescuing "nil" when no exception class was found.
This does work in 1.9.3, but does not in 2.0, raising an exception
asking for a class or module to be given to the rescue clause.
Thanks @yahonda for catching this.
-rw-r--r-- | activerecord/lib/active_record/tasks/mysql_database_tasks.rb | 22 |
1 files changed, 13 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 1b4ed1cac4..17378969a5 100644 --- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb @@ -15,18 +15,20 @@ module ActiveRecord establish_connection configuration_without_database connection.create_database configuration['database'], creation_options establish_connection configuration - rescue error_class => error - raise error unless error.errno == ACCESS_DENIED_ERROR - - $stdout.print error.error - establish_connection root_configuration_without_database - connection.create_database configuration['database'], creation_options - connection.execute grant_statement.gsub(/\s+/, ' ').strip - establish_connection configuration - rescue ActiveRecord::StatementInvalid, error_class => error + rescue ActiveRecord::StatementInvalid => error if /database exists/ === error.message raise DatabaseAlreadyExists else + raise + end + rescue error_class => error + if error.respond_to?(:errno) && error.errno == ACCESS_DENIED_ERROR + $stdout.print error.error + establish_connection root_configuration_without_database + connection.create_database configuration['database'], creation_options + connection.execute grant_statement.gsub(/\s+/, ' ').strip + establish_connection configuration + else $stderr.puts "Couldn't create database for #{configuration.inspect}, #{creation_options.inspect}" $stderr.puts "(If you set the charset manually, make sure you have a matching collation)" if configuration['encoding'] end @@ -96,6 +98,8 @@ module ActiveRecord Mysql2::Error elsif defined?(Mysql) Mysql::Error + else + StandardError end end |