New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rake db:test:purge creates mysql database with wrong charset & collation #1952

Merged
merged 1 commit into from Jul 6, 2011
Jump to file or symbol
Failed to load files and symbols.
+8 −5
Diff settings

Always

Just for now

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.
  • Loading branch information...
simonbaird committed Jul 4, 2011
commit 3ba3125b24b532876c95c8d9d00c9b69faab5a60
@@ -35,6 +35,12 @@ 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/
@@ -58,9 +64,6 @@ namespace :db do
rescue
case config['adapter']
when /^(jdbc)?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'
@@ -71,7 +74,7 @@ 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
@@ -435,7 +438,7 @@ namespace :db do
case abcs["test"]["adapter"]
when /^(jdbc)?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 /^(jdbc)?postgresql$/
ActiveRecord::Base.clear_active_connections!
drop_database(abcs['test'])
ProTip! Use n and p to navigate between commits in a pull request.