diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2011-07-06 20:10:14 -0700 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-07-06 20:10:14 -0700 |
commit | c6578d64ca13e5089897b06a84e35a313caff84b (patch) | |
tree | 702833ede1fbaf48b51705ecf044defc8cac9195 /activerecord | |
parent | 35597e3606e72c1a32e2a4573f5da009377ac037 (diff) | |
parent | ecd37084b28a05f052510e2a96e263d1eef74f0a (diff) | |
download | rails-c6578d64ca13e5089897b06a84e35a313caff84b.tar.gz rails-c6578d64ca13e5089897b06a84e35a313caff84b.tar.bz2 rails-c6578d64ca13e5089897b06a84e35a313caff84b.zip |
Merge pull request #1989 from simonbaird/master
rake db:test:purge creates mysql database with wrong charset & collation (master branch)
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 399f3c5d03..44e5520230 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -44,6 +44,12 @@ db_namespace = namespace :db do create_database(ActiveRecord::Base.configurations[Rails.env]) end + def mysql_creation_options(config) + @charset = ENV['CHARSET'] || 'utf8' + @collation = ENV['COLLATION'] || 'utf8_unicode_ci' + {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)} + end + def create_database(config) begin if config['adapter'] =~ /sqlite/ @@ -67,9 +73,6 @@ db_namespace = namespace :db do rescue case config['adapter'] when /mysql/ - @charset = ENV['CHARSET'] || 'utf8' - @collation = ENV['COLLATION'] || 'utf8_unicode_ci' - creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)} if config['adapter'] =~ /jdbc/ #FIXME After Jdbcmysql gives this class require 'active_record/railties/jdbcmysql_error' @@ -80,7 +83,7 @@ db_namespace = namespace :db do access_denied_error = 1045 begin ActiveRecord::Base.establish_connection(config.merge('database' => nil)) - ActiveRecord::Base.connection.create_database(config['database'], creation_options) + ActiveRecord::Base.connection.create_database(config['database'], mysql_creation_options(config)) ActiveRecord::Base.establish_connection(config) rescue error_class => sqlerr if sqlerr.errno == access_denied_error @@ -443,7 +446,7 @@ db_namespace = namespace :db do case abcs['test']['adapter'] when /mysql/ ActiveRecord::Base.establish_connection(:test) - ActiveRecord::Base.connection.recreate_database(abcs['test']['database'], abcs['test']) + ActiveRecord::Base.connection.recreate_database(abcs['test']['database'], mysql_creation_options(abcs['test'])) when /postgresql/ ActiveRecord::Base.clear_active_connections! drop_database(abcs['test']) |