提交 6a9301dc 编写于 作者: R Ryuta Kamizono

Backward compatibility to work `Marshal.load(legacy_record.dump)` for MySQL

Context https://github.com/rails/rails/pull/39599#discussion_r445429365.

Similar with #39611.

Actually we never said we would keep Mashal compatibility between two
versions of Rails, so we sometimes directly removed the dedicated types
in the past (e.g. f1a0fa9e, #29666), but that direct removing makes cache
rotation harder.

Keeping the unused constant in new version at least during one version
will help cache rotation easier.
上级 5e2df1fc
......@@ -844,6 +844,10 @@ def version_string(full_version_string)
full_version_string.match(/^(?:5\.5\.5-)?(\d+\.\d+\.\d+)/)[1]
end
# Alias MysqlString to work Mashal.load(File.read("legacy_record.dump")).
# TODO: Remove the constant alias once Rails 6.1 has released.
MysqlString = Type::String # :nodoc:
ActiveRecord::Type.register(:immutable_string, adapter: :mysql2) do |_, **args|
Type::ImmutableString.new(true: "1", false: "0", **args)
end
......
......@@ -1226,6 +1226,21 @@ def test_marshalling_with_associations
assert_equal 1, post.comments.length
end
if current_adapter?(:Mysql2Adapter)
def test_marshal_load_legacy_6_0_record_mysql
path = File.expand_path(
"support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump",
TEST_ROOT
)
topic = Marshal.load(File.read(path))
assert_not_predicate topic, :new_record?
assert_equal 1, topic.id
assert_equal "The First Topic", topic.title
assert_equal "Have a nice day", topic.content
end
end
if Process.respond_to?(:fork) && !in_memory_db?
def test_marshal_between_processes
# Define a new model to ensure there are no caches
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册