Skip to content

Commit

Permalink
Merge pull request rails#28733 from kamipo/dont_fallback_to_utf8mb3_a…
Browse files Browse the repository at this point in the history
…fter_mysql_8.0.0

Don't fallback to utf8mb3 after MySQL 8.0.0
  • Loading branch information
rafaelfranca authored Apr 20, 2017
2 parents d87d0e3 + a8ee3e8 commit 5816c20
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ def initialize(connection, logger, connection_options, config)
end
end

CHARSETS_OF_4BYTES_MAXLEN = ["utf8mb4", "utf16", "utf16le", "utf32"]

def internal_string_options_for_primary_key # :nodoc:
super.tap { |options|
options[:collation] = collation.sub(/\A[^_]+/, "utf8") if CHARSETS_OF_4BYTES_MAXLEN.include?(charset)
}
end

def version #:nodoc:
@version ||= Version.new(full_version.match(/^\d+\.\d+\.\d+/)[0])
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ def indexes(table_name, name = nil)
indexes
end

def internal_string_options_for_primary_key
super.tap do |options|
if CHARSETS_OF_4BYTES_MAXLEN.include?(charset) && (mariadb? || version < "8.0.0")
options[:collation] = collation.sub(/\A[^_]+/, "utf8")
end
end
end

private
CHARSETS_OF_4BYTES_MAXLEN = ["utf8mb4", "utf16", "utf16le", "utf32"]

def schema_creation
MySQL::SchemaCreation.new(self)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_initializes_schema_migrations_for_encoding_utf8mb4

ActiveRecord::SchemaMigration.create_table

assert connection.column_exists?(table_name, :version, :string, collation: "utf8_general_ci")
assert connection.column_exists?(table_name, :version, :string)
end
end

Expand All @@ -29,7 +29,7 @@ def test_initializes_internal_metadata_for_encoding_utf8mb4

ActiveRecord::InternalMetadata.create_table

assert connection.column_exists?(table_name, :key, :string, collation: "utf8_general_ci")
assert connection.column_exists?(table_name, :key, :string)
end
end

Expand Down

0 comments on commit 5816c20

Please sign in to comment.