Browse files

Fix database rake tasks to work with charset/collation and show prope…

…r error messages on failure. Closes #11301 [matt]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9004 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 8e21ec3 commit 3d2177df26c8934320277a7aed84595decd94662 @lifo lifo committed Mar 10, 2008
Showing with 10 additions and 3 deletions.
  1. +2 −0 railties/CHANGELOG
  2. +8 −3 railties/lib/tasks/databases.rake
View
2 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]
View
11 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)

0 comments on commit 3d2177d

Please sign in to comment.