mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
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.
(Cherry pick of 3ba3125b24)
This commit is contained in:
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user