Skip to content
This repository
Browse code

Merge pull request #1989 from simonbaird/master

rake db:test:purge creates mysql database with wrong charset & collation (master branch)
  • Loading branch information...
commit c6578d64ca13e5089897b06a84e35a313caff84b 2 parents 35597e3 + ecd3708
Santiago Pastorino spastorino authored

Showing 1 changed file with 8 additions and 5 deletions. Show diff stats Hide diff stats

  1. +8 5 activerecord/lib/active_record/railties/databases.rake
13 activerecord/lib/active_record/railties/databases.rake
@@ -44,6 +44,12 @@ db_namespace = namespace :db do
44 44 create_database(ActiveRecord::Base.configurations[Rails.env])
45 45 end
46 46
  47 + def mysql_creation_options(config)
  48 + @charset = ENV['CHARSET'] || 'utf8'
  49 + @collation = ENV['COLLATION'] || 'utf8_unicode_ci'
  50 + {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
  51 + end
  52 +
47 53 def create_database(config)
48 54 begin
49 55 if config['adapter'] =~ /sqlite/
@@ -67,9 +73,6 @@ db_namespace = namespace :db do
67 73 rescue
68 74 case config['adapter']
69 75 when /mysql/
70   - @charset = ENV['CHARSET'] || 'utf8'
71   - @collation = ENV['COLLATION'] || 'utf8_unicode_ci'
72   - creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
73 76 if config['adapter'] =~ /jdbc/
74 77 #FIXME After Jdbcmysql gives this class
75 78 require 'active_record/railties/jdbcmysql_error'
@@ -80,7 +83,7 @@ db_namespace = namespace :db do
80 83 access_denied_error = 1045
81 84 begin
82 85 ActiveRecord::Base.establish_connection(config.merge('database' => nil))
83   - ActiveRecord::Base.connection.create_database(config['database'], creation_options)
  86 + ActiveRecord::Base.connection.create_database(config['database'], mysql_creation_options(config))
84 87 ActiveRecord::Base.establish_connection(config)
85 88 rescue error_class => sqlerr
86 89 if sqlerr.errno == access_denied_error
@@ -443,7 +446,7 @@ db_namespace = namespace :db do
443 446 case abcs['test']['adapter']
444 447 when /mysql/
445 448 ActiveRecord::Base.establish_connection(:test)
446   - ActiveRecord::Base.connection.recreate_database(abcs['test']['database'], abcs['test'])
  449 + ActiveRecord::Base.connection.recreate_database(abcs['test']['database'], mysql_creation_options(abcs['test']))
447 450 when /postgresql/
448 451 ActiveRecord::Base.clear_active_connections!
449 452 drop_database(abcs['test'])

0 comments on commit c6578d6

Please sign in to comment.
Something went wrong with that request. Please try again.