Last active
February 12, 2025 06:24
-
-
Save spickermann/4433125 to your computer and use it in GitHub Desktop.
Ruby On Rails - default charset migration
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
class SetDatabaseDefaults < ActiveRecord::Migration | |
def up | |
case ActiveRecord::Base.connection.adapter_name | |
when "MySQL", "Mysql2" | |
execute "ALTER DATABASE #{current_database} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci" | |
when "SQLite" | |
# do nothing since SQLite does not support changing the database encoding and only supports unicode charsets | |
when "PostgreSQL" | |
# do nothing since PostgreSQL does not support changing the database encoding | |
end | |
end | |
def down | |
raise ActiveRecord::IrreversibleMigration | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment