lib/chrono_model/adapter.rb in chrono_model-0.12.2 vs lib/chrono_model/adapter.rb in chrono_model-0.12.3

- old
+ new

@@ -104,13 +104,11 @@ # execute "DROP VIEW #{name}" # Drop functions # - %w( insert update delete ).each do |func| - execute "DROP FUNCTION chronomodel_#{name}_#{func}()" - end + chrono_drop_trigger_functions_for(name) # Create view and functions # chrono_create_view_for(new_name) end @@ -166,15 +164,11 @@ if options[:temporal] == false && is_chrono?(table_name) # Remove temporal features from this table # execute "DROP VIEW #{table_name}" - _on_temporal_schema do - %w( insert update delete ).each do |func| - execute "DROP FUNCTION IF EXISTS #{table_name}_#{func}() CASCADE" - end - end + chrono_drop_trigger_functions_for(table_name) _on_history_schema { execute "DROP TABLE #{table_name}" } default_schema = select_value 'SELECT current_schema()' _on_temporal_schema do @@ -196,10 +190,12 @@ # def drop_table(table_name, *) return super unless is_chrono?(table_name) _on_temporal_schema { execute "DROP TABLE #{table_name} CASCADE" } + + chrono_drop_trigger_functions_for(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. @@ -848,9 +844,15 @@ DROP TRIGGER IF EXISTS chronomodel_delete ON #{table}; CREATE TRIGGER chronomodel_delete INSTEAD OF DELETE ON #{table} FOR EACH ROW EXECUTE PROCEDURE chronomodel_#{table}_delete(); SQL + end + + def chrono_drop_trigger_functions_for(table_name) + %w( insert update delete ).each do |func| + execute "DROP FUNCTION IF EXISTS chronomodel_#{table_name}_#{func}()" + end end # In destructive changes, such as removing columns or changing column # types, the view must be dropped and recreated, while the change has # to be applied to the table in the temporal schema.