Skip to content

Instantly share code, notes, and snippets.

@richhollis
Created October 25, 2013 11:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richhollis/7153490 to your computer and use it in GitHub Desktop.
Save richhollis/7153490 to your computer and use it in GitHub Desktop.
tables = [] # or ActiveRecord::Base.connection.tables
collation = "utf8_unicode_ci"
char_set = "utf8"
db = "your_database_name"
# write out
puts "USE #{db};"
puts "ALTER DATABASE #{db} CHARACTER SET #{char_set} COLLATE #{collation};"
tables.each do |t|
puts "ALTER TABLE #{t} CHARACTER SET #{char_set} COLLATE #{collation};" # changes for new records
puts "ALTER TABLE #{t} CONVERT TO CHARACTER SET #{char_set} COLLATE #{collation};" # migrates old records
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment