diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2019-03-13 14:08:54 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2019-03-13 14:17:31 -0400 |
commit | e5f1b363d2b9983ad42b7d32185a6a731f5e383c (patch) | |
tree | ed309028ba80393db88b1760c3bfecd98ffea17b | |
parent | a2bd669ed240bec739074188d61ff125e07fa8d1 (diff) | |
download | rails-e5f1b363d2b9983ad42b7d32185a6a731f5e383c.tar.gz rails-e5f1b363d2b9983ad42b7d32185a6a731f5e383c.tar.bz2 rails-e5f1b363d2b9983ad42b7d32185a6a731f5e383c.zip |
Revert "Remove Marshal support from SchemaCache"
This reverts commit 65f2eeaaf5774f0891fff700f4defb0b90a05789.
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/schema_cache.rb | 11 | ||||
-rw-r--r-- | activerecord/test/cases/connection_adapters/schema_cache_test.rb | 18 |
2 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb index 5b598620d3..07453b4403 100644 --- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb @@ -114,6 +114,17 @@ module ActiveRecord @indexes.delete name end + def marshal_dump + # if we get current version during initialization, it happens stack over flow. + @version = connection.migration_context.current_version + [@version, @columns, @columns_hash, @primary_keys, @data_sources, @indexes] + end + + def marshal_load(array) + @version, @columns, @columns_hash, @primary_keys, @data_sources, @indexes = array + @indexes = @indexes || {} + end + private def prepare_data_sources connection.data_sources.each { |source| @data_sources[source] = true } diff --git a/activerecord/test/cases/connection_adapters/schema_cache_test.rb b/activerecord/test/cases/connection_adapters/schema_cache_test.rb index 722db1f69f..5113548091 100644 --- a/activerecord/test/cases/connection_adapters/schema_cache_test.rb +++ b/activerecord/test/cases/connection_adapters/schema_cache_test.rb @@ -86,6 +86,24 @@ module ActiveRecord assert_equal 0, @cache.size end + def test_dump_and_load + @cache.columns("posts") + @cache.columns_hash("posts") + @cache.data_sources("posts") + @cache.primary_keys("posts") + @cache.indexes("posts") + + @cache = Marshal.load(Marshal.dump(@cache)) + + assert_no_queries do + assert_equal 12, @cache.columns("posts").size + assert_equal 12, @cache.columns_hash("posts").size + assert @cache.data_sources("posts") + assert_equal "id", @cache.primary_keys("posts") + assert_equal 1, @cache.indexes("posts").size + end + end + def test_data_source_exist assert @cache.data_source_exists?("posts") assert_not @cache.data_source_exists?("foo") |