From 66f8156b0360fe5fd9225fd0b96646dfbe89aa82 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Tue, 2 May 2017 13:39:02 +0900 Subject: [PATCH] Introduce PgAuditLog::AUDITED_EVENTS By modifying this constant user could opt out of some events they don't need to audit. --- lib/pg_audit_log.rb | 6 ++++++ lib/pg_audit_log/triggers.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/pg_audit_log.rb b/lib/pg_audit_log.rb index 11d0c0d..b4e0cb1 100644 --- a/lib/pg_audit_log.rb +++ b/lib/pg_audit_log.rb @@ -4,6 +4,12 @@ module PgAuditLog 'sessions'.freeze, 'schema_migrations'.freeze, ] + + AUDITED_EVENTS = %w[ + INSERT + UPDATE + DELETE + ] end require 'active_record' diff --git a/lib/pg_audit_log/triggers.rb b/lib/pg_audit_log/triggers.rb index 7e71e3d..5cd2f4c 100644 --- a/lib/pg_audit_log/triggers.rb +++ b/lib/pg_audit_log/triggers.rb @@ -72,7 +72,7 @@ def create_for_table(table_name) return if tables_with_triggers.include?(table_name) execute <<-SQL CREATE TRIGGER #{trigger_name_for_table(table_name)} - AFTER INSERT OR UPDATE OR DELETE + AFTER #{AUDITED_EVENTS.join(' OR ')} ON #{table_name} FOR EACH ROW EXECUTE PROCEDURE #{PgAuditLog::Function.name}()