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 9dbed2c1b770897e067823f15dae2e9a143f66c3..39af3a02cf2ecf12b5951ccb896bdf4396955be6 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -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 diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index f8f3e86acc9c134a80c21f368ed5c1da87fdc5db..5e948224d7f22d7189ca09c1e3b3cca24d403923 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -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 diff --git a/activerecord/test/support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump b/activerecord/test/support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump new file mode 100644 index 0000000000000000000000000000000000000000..72ebbd88d0ea24dcfa68b94ea4cbd865cc1dd699 Binary files /dev/null and b/activerecord/test/support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump differ