Navigation Menu

Skip to content

Commit

Permalink
Fix database rake tasks to work with charset/collation and show prope…
Browse files Browse the repository at this point in the history
…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
lifo committed Mar 10, 2008
1 parent 8e21ec3 commit 3d2177d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions 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]
Expand Down
11 changes: 8 additions & 3 deletions railties/lib/tasks/databases.rake
Expand Up @@ -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`
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3d2177d

Please sign in to comment.