Create database in utf8 even if DATABASE_ENCODING is utf8mb4.

This is because we specify the `utf8mb4` charset in some of the columns
and expect others to be defaulted to `utf8`.

I'd like to make this a feature of `ar_mysql_column_charset`.  If you
want to set a table charset, you can always pass a keyword option
`options: "default charset=utf8mb4"` to `create_table`.

Complements #414.
This commit is contained in:
Akinori MUSHA 2014-10-01 21:20:39 +09:00
parent 7fc9fbb2d6
commit 41eb277475

View file

@ -63,6 +63,15 @@ module ActiveRecord::ConnectionAdapters
end
}
end
def create_database(name, options = {})
# utf8mb4 is used in column definitions; use utf8 for
# databases.
if options[:charset] == 'utf8mb4'
options = options.merge(charset: 'utf8')
end
super(name, options)
end
end
prepend CharsetSupport