Skip to content

Instantly share code, notes, and snippets.

@aratak
Created March 29, 2012 11:43
Show Gist options
  • Save aratak/2236348 to your computer and use it in GitHub Desktop.
Save aratak/2236348 to your computer and use it in GitHub Desktop.
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