diff options
author | kennyj <kennyj@gmail.com> | 2012-03-01 00:52:04 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-03-01 00:52:04 +0900 |
commit | 5ca4fc95818047108e69e22d200e7a4a22969477 (patch) | |
tree | abe1f7d9dda0e93cf007fcc5b24e686abcc54287 /activerecord/lib/active_record/connection_adapters | |
parent | 8cecb476966b7ec61a31fd08e96afb67931eac3d (diff) | |
download | rails-5ca4fc95818047108e69e22d200e7a4a22969477.tar.gz rails-5ca4fc95818047108e69e22d200e7a4a22969477.tar.bz2 rails-5ca4fc95818047108e69e22d200e7a4a22969477.zip |
Add support schema cache dump and load.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/schema_cache.rb | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb index 962718da56..fd0dbd7d78 100644 --- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb @@ -6,21 +6,12 @@ module ActiveRecord def initialize(conn) @connection = conn - @tables = {} - @columns = Hash.new do |h, table_name| - h[table_name] = conn.columns(table_name) - end - - @columns_hash = Hash.new do |h, table_name| - h[table_name] = Hash[columns[table_name].map { |col| - [col.name, col] - }] - end - - @primary_keys = Hash.new do |h, table_name| - h[table_name] = table_exists?(table_name) ? conn.primary_key(table_name) : nil - end + @columns = {} + @columns_hash = {} + @primary_keys = {} + @tables = {} + prepare_default_proc end # A cached lookup for table existence. @@ -45,6 +36,35 @@ module ActiveRecord @primary_keys.delete table_name @tables.delete table_name end + + def marshal_dump + [:@columns, :@columns_hash, :@primary_keys, :@tables].map do |val| + self.instance_variable_get(val).inject({}) { |h, v| h[v[0]] = v[1]; h } + end + end + + def marshal_load(array) + @columns, @columns_hash, @primary_keys, @tables = array + prepare_default_proc + end + + private + + def prepare_default_proc + @columns.default_proc = Proc.new do |h, table_name| + h[table_name] = connection.columns(table_name) + end + + @columns_hash.default_proc = Proc.new do |h, table_name| + h[table_name] = Hash[columns[table_name].map { |col| + [col.name, col] + }] + end + + @primary_keys.default_proc = Proc.new do |h, table_name| + h[table_name] = table_exists?(table_name) ? connection.primary_key(table_name) : nil + end + end end end end |