Skip to content

Instantly share code, notes, and snippets.

@ctrlaltdylan
Created July 21, 2020 15:37
Show Gist options
  • Save ctrlaltdylan/0c385e8bc70d3710b5c68f7f63e097a2 to your computer and use it in GitHub Desktop.
Save ctrlaltdylan/0c385e8bc70d3710b5c68f7f63e097a2 to your computer and use it in GitHub Desktop.
Change whole MySQL database collation to utf8mb4 with LHM
class ChangeCollationDbWide < ActiveRecord::Migration[5.2]
def change
db = ActiveRecord::Base.connection
tables = ActiveRecord::Base.connection.tables.map { |t| t.to_sym }
tables.each do |t|
Lhm.change_table(t) do |table|
table.ddl "ALTER TABLE `#{table.name}` DEFAULT CHARACTER SET utf8mb4, DEFAULT COLLATE utf8mb4_unicode_ci"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment