diff options
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/lib/tasks/databases.rake | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index f2bd7d6930..bfc066e6f1 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix database rake tasks to work with charset/collation and show proper error messages on failure. Closes #11301 [matt] + * add a -e/--export to script/plugin install, uses svn export. #10847 [jon@blankpad.net)] * Add config.time_zone for configuring the default Time.zone value. #10982 [Geoff Buesing] diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 00c0fa4072..73259ee34d 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -37,10 +37,10 @@ namespace :db do @collation = ENV['COLLATION'] || 'utf8_general_ci' begin ActiveRecord::Base.establish_connection(config.merge({'database' => nil})) - ActiveRecord::Base.connection.create_database(config['database'], {:charset => @charset, :collation => @collation}) + ActiveRecord::Base.connection.create_database(config['database'], {:charset => (config['database']['charset'] || @charset), :collation => (config['database']['charset'] || @collation)}) ActiveRecord::Base.establish_connection(config) rescue - $stderr.puts "Couldn't create database for #{config.inspect}" + $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{@charset}, collation: #{@collation} (if you set the charset manually, make sure you have a matching collation)" end when 'postgresql' `createdb "#{config['database']}" -E utf8` @@ -68,7 +68,12 @@ namespace :db do desc 'Drops the database for the current RAILS_ENV' task :drop => :environment do - drop_database(ActiveRecord::Base.configurations[RAILS_ENV || 'development']) + config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] + begin + drop_database(config) + rescue Exception => e + puts "Couldn't drop #{config['database']} : #{e.inspect}" + end end def local_database?(config, &block) |