-
-
Save dmitriy-kiriyenko/2236432 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')) | |
charset = ENV["CHARSET"] || "utf8" | |
collation = ENV["COLLATION"] || "ut8_unicode_ci" | |
puts "Starting... charset will be set to #{charset}, collation to #{collaction}" | |
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 #{charset} COLLATE #{collation}\;") | |
ActiveRecord::Base.connection.tables.each do |table| | |
ActiveRecord::Base.connection.execute("ALTER TABLE `#{table}` CONVERT TO CHARACTER SET #{charset} COLLATE #{collation}\;")} | |
print "*" | |
end | |
puts "Successfully converted database charset to #{charset} and collation to #{collation}" |
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
curl https://raw.github.com/gist/2236348/d3c799bb63a2b84d40004ae2bc0b36f640786dd4/mysql-collation-fix.rb | ruby | |
# or | |
https://raw.github.com/gist/2236348/d3c799bb63a2b84d40004ae2bc0b36f640786dd4/mysql-collation-fix.rb | RAILS_ENV=production ruby | |
# or | |
https://raw.github.com/gist/2236348/d3c799bb63a2b84d40004ae2bc0b36f640786dd4/mysql-collation-fix.rb | RAILS_ENV=production CHARSET=win1251 COLLATION=win1251_ci ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment