Created
March 29, 2012 11:43
-
-
Save aratak/2236348 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path(File.join(File.dirname(__FILE__), 'config', 'environment')) | |
if File.exist?('config/database.yml') | |
database_platform = YAML.load_file(File.join("config/database.yml"))[Rails.env] | |
database_platform.delete("socket") | |
ActiveRecord::Base.establish_connection(database_platform) | |
ActiveRecord::Base.connection.execute("ALTER DATABASE `#{database_platform['database']}` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci\;") | |
ActiveRecord::Base.connection.tables.each {|table|ActiveRecord::Base.connection.execute("ALTER TABLE `#{table}` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci\;")} | |
puts "Successfully converting database collation" | |
else | |
puts "Database configuration doesn't exist ('config/database.yml')\nExiting" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment