Skip to content
This repository
Browse code

Fix charset/collate in mysql recreate_database

See new method mysql_creation_options. It is used by both
create_database and recreate_database so they are consistent.

(Manual cherry pick of 3ba3125)
  • Loading branch information...
commit f44c3ea4572f509d0aae2b72afab84f8ae69f5b8 1 parent d764378
Simon Baird simonbaird 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 f44c3ea

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