diff options
author | Jeremy Daer <jeremydaer@gmail.com> | 2018-09-13 10:17:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-13 10:17:59 -0700 |
commit | f89e2c2cba429efd62e9d6e2c4c96afa205c5135 (patch) | |
tree | a38e01894785701c1b80bb57791ec75a522dab8a /activerecord | |
parent | 51b01dd179937e55c17583ebd70a455860ea83e0 (diff) | |
parent | a338314d31b2a6d0f3cefcfc8c897369094098e4 (diff) | |
download | rails-f89e2c2cba429efd62e9d6e2c4c96afa205c5135.tar.gz rails-f89e2c2cba429efd62e9d6e2c4c96afa205c5135.tar.bz2 rails-f89e2c2cba429efd62e9d6e2c4c96afa205c5135.zip |
Merge pull request #33853 from yahonda/use_utf8mb4_only_if_available
Validate if `utf8mb4` character set and longer index key prefix is supported
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 18 |
2 files changed, 19 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 0bb5dfe313..942a6ca282 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Bump minimum MySQL version to 5.5.8. + + *Yasuo Honda* + * Use MySQL utf8mb4 character set by default. `utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji. diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 2d287d56e8..5d4fc8324f 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -53,8 +53,8 @@ module ActiveRecord @statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit])) - if version < "5.1.10" - raise "Your version of MySQL (#{version_string}) is too old. Active Record supports MySQL >= 5.1.10." + if version < "5.5.8" + raise "Your version of MySQL (#{version_string}) is too old. Active Record supports MySQL >= 5.5.8." end end @@ -114,6 +114,14 @@ module ActiveRecord 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 @@ module ActiveRecord 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')}" + raise "Configure a supported :charset and ensure innodb_large_prefix is enabled to support indexes on varchar(255) string columns." end end |