Module: ActivePgLog::ActiveLog
- Defined in:
- lib/active_pg_log/active_log.rb
Overview
ActiveLog doc
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create_log_ddl_trigger(clazz) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/active_pg_log/active_log.rb', line 24 def create_log_ddl_trigger(clazz) %( drop trigger if exists trigger_log_#{clazz.table_name}_insert_update on #{clazz.table_name} cascade; CREATE TRIGGER trigger_log_#{clazz.table_name}_insert_update after insert or update on #{clazz.table_name} for each row execute procedure public.active_pg_loging(); ) end |
.included(clazz) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/active_pg_log/active_log.rb', line 6 def self.included(clazz) @active_trigger = ActivePgLog::ActiveTrigger.new(clazz.connection) return if @active_trigger.include?("trigger_log_#{clazz.table_name}_insert_update", clazz.table_name) clazz.connection.execute(create_log_ddl_trigger(clazz)) end |
Instance Method Details
#disable_log_ddl_trigger(clazz) ⇒ Object
14 15 16 17 |
# File 'lib/active_pg_log/active_log.rb', line 14 def disable_log_ddl_trigger(clazz) clazz.connection.execute("drop trigger if exists trigger_log_#{self.class.table_name}_insert_update on #{self.class.table_name} cascade;") nil end |
#pg_logs ⇒ Object
19 20 21 |
# File 'lib/active_pg_log/active_log.rb', line 19 def pg_logs ActivePgLogTable.where(table_name: self.class.table_name) end |