lib/chrono_model/adapter.rb in chrono_model-0.12.0 vs lib/chrono_model/adapter.rb in chrono_model-0.12.1

- old
+ new

@@ -44,12 +44,10 @@ transaction do _on_temporal_schema { super } _on_history_schema { chrono_create_history_for(table_name) } chrono_create_view_for(table_name, options) - - TableCache.add! table_name end end # If renaming a temporal table, rename the history and view as well. # @@ -113,13 +111,10 @@ end # Create view and functions # chrono_create_view_for(new_name) - - TableCache.del! name - TableCache.add! new_name end end # If changing a temporal table, redirect the change to the table in the # temporal schema and recreate views. @@ -146,12 +141,10 @@ execute "ALTER TABLE #{table_name} SET SCHEMA #{TEMPORAL_SCHEMA}" _on_history_schema { chrono_create_history_for(table_name) } chrono_create_view_for(table_name, options) copy_indexes_to_history_for(table_name) - TableCache.add! table_name - # Optionally copy the plain table data, setting up history # retroactively. # if options[:copy_data] seq = _on_history_schema { serial_sequence(table_name, primary_key(table_name)) } @@ -189,12 +182,10 @@ execute "ALTER TABLE #{table_name} DROP __chrono_id" end execute "ALTER TABLE #{table_name} SET SCHEMA #{default_schema}" end - - TableCache.del! table_name end super table_name, options, &block end end @@ -205,12 +196,10 @@ # def drop_table(table_name, *) return super unless is_chrono?(table_name) _on_temporal_schema { execute "DROP TABLE #{table_name} CASCADE" } - - TableCache.del! table_name end # If adding an index to a temporal table, add it to the one in the # temporal schema and to the history one. If the `:unique` option is # present, it is removed from the index created in the history table. @@ -450,23 +439,14 @@ end end @_on_schema_nesting -= 1 end - TableCache = (Class.new(Hash) do - def all ; keys; ; end - def add! table ; self[table.to_s] = true ; end - def del! table ; self[table.to_s] = nil ; end - def fetch table ; self[table.to_s] ||= yield ; end - end).new - # Returns true if the given name references a temporal table. # def is_chrono?(table) - TableCache.fetch(table) do - _on_temporal_schema { chrono_data_source_exists?(table) } && + _on_temporal_schema { chrono_data_source_exists?(table) } && _on_history_schema { chrono_data_source_exists?(table) } - end rescue ActiveRecord::StatementInvalid => e # means that we could not change the search path to check for # table existence if is_exception_class?(e, PG::InvalidSchemaName, PG::InvalidParameterValue)