提交 be021a80 编写于 作者: Y Yasuo Honda

Validate if `utf8mb4` character set and longer index key prefix is supported

Once #33608 merged If users create a new database using MySQL 5.1.x, it will fail to create databases
since MySQL 5.1 does not know `utf8mb4` character set.

This pull request removes `encoding: utf8mb4` from `mysql.yml.tt`
to let create_database method handles default character set by MySQL server version.

`supports_longer_index_key_prefix?` method will need to validate if MySQL 5.5 and 5.6 server configured
correctly to support longer index key prefix, but not yet.
上级 7db3a6e8
......@@ -114,6 +114,14 @@ def supports_advisory_locks?
true
end
def supports_longer_index_key_prefix?
if mariadb?
version >= "10.2.2"
else
version >= "5.7.9"
end
end
def get_advisory_lock(lock_name, timeout = 0) # :nodoc:
query_value("SELECT GET_LOCK(#{quote(lock_name.to_s)}, #{timeout})") == 1
end
......@@ -250,8 +258,12 @@ def recreate_database(name, options = {})
def create_database(name, options = {})
if options[:collation]
execute "CREATE DATABASE #{quote_table_name(name)} DEFAULT COLLATE #{quote_table_name(options[:collation])}"
elsif options[:charset]
execute "CREATE DATABASE #{quote_table_name(name)} DEFAULT CHARACTER SET #{quote_table_name(options[:charset])}"
elsif supports_longer_index_key_prefix?
execute "CREATE DATABASE #{quote_table_name(name)} DEFAULT CHARACTER SET `utf8mb4`"
else
execute "CREATE DATABASE #{quote_table_name(name)} DEFAULT CHARACTER SET #{quote_table_name(options[:charset] || 'utf8mb4')}"
execute "CREATE DATABASE #{quote_table_name(name)} DEFAULT CHARACTER SET `utf8`"
end
end
......
......@@ -11,7 +11,6 @@
#
default: &default
adapter: mysql2
encoding: utf8mb4
pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册