From 4b30accf510beff0c97c4b61e5b3a59ea6686381 Mon Sep 17 00:00:00 2001 From: "Paul A. Jungwirth" Date: Mon, 6 Jun 2016 16:35:05 -0700 Subject: [PATCH 1/3] Don't load columns from tables in other schemas --- lib/pg_audit_log/function.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pg_audit_log/function.rb b/lib/pg_audit_log/function.rb index f96a29c..377967e 100644 --- a/lib/pg_audit_log/function.rb +++ b/lib/pg_audit_log/function.rb @@ -75,7 +75,7 @@ def install INTO primary_key_column USING TG_RELNAME; primary_key_value := NULL; - FOR col IN SELECT * FROM information_schema.columns WHERE table_name = TG_RELNAME LOOP + FOR col IN SELECT * FROM information_schema.columns WHERE table_name = TG_RELNAME AND table_schema = 'public' LOOP new_value := NULL; old_value := NULL; column_name := col.column_name; From 47666fa7ca0790344ac7b6801f2f54b74a9722bc Mon Sep 17 00:00:00 2001 From: "Paul A. Jungwirth" Date: Tue, 7 Jun 2016 08:26:57 -0700 Subject: [PATCH 2/3] Preserve old behavior watching all schemas unless user says otherwise --- .../pg_audit_log/templates/lib/tasks/pg_audit_log.rake | 2 +- lib/pg_audit_log/function.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/generators/pg_audit_log/templates/lib/tasks/pg_audit_log.rake b/lib/generators/pg_audit_log/templates/lib/tasks/pg_audit_log.rake index f022ad0..276a115 100644 --- a/lib/generators/pg_audit_log/templates/lib/tasks/pg_audit_log.rake +++ b/lib/generators/pg_audit_log/templates/lib/tasks/pg_audit_log.rake @@ -7,7 +7,7 @@ namespace :pg_audit_log do end puts "Installing audit_changes() function..." - PgAuditLog::Function.install + PgAuditLog::Function.install(ENV['PG_AUDIT_LOG_SCHEMA'].presence) puts "Installing all audit log triggers... " PgAuditLog::Triggers.install diff --git a/lib/pg_audit_log/function.rb b/lib/pg_audit_log/function.rb index 377967e..9cda9e7 100644 --- a/lib/pg_audit_log/function.rb +++ b/lib/pg_audit_log/function.rb @@ -43,7 +43,8 @@ def user_unique_name_temporary_function(username) end end - def install + def install(only_audit_schema=nil) + schema_restriction = only_audit_schema ? "AND TABLE_schema = '#{only_audit_schema}'" : "" execute <<-SQL CREATE OR REPLACE PROCEDURAL LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION #{name}() RETURNS trigger @@ -75,7 +76,7 @@ def install INTO primary_key_column USING TG_RELNAME; primary_key_value := NULL; - FOR col IN SELECT * FROM information_schema.columns WHERE table_name = TG_RELNAME AND table_schema = 'public' LOOP + FOR col IN SELECT * FROM information_schema.columns WHERE table_name = TG_RELNAME #{schema_restriction} LOOP new_value := NULL; old_value := NULL; column_name := col.column_name; From 4776cc80067de215cfbf84923d9b4f28fdfb6698 Mon Sep 17 00:00:00 2001 From: "Paul A. Jungwirth" Date: Tue, 7 Jun 2016 08:34:29 -0700 Subject: [PATCH 3/3] Fix strange capitalization --- lib/pg_audit_log/function.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pg_audit_log/function.rb b/lib/pg_audit_log/function.rb index 9cda9e7..30c741f 100644 --- a/lib/pg_audit_log/function.rb +++ b/lib/pg_audit_log/function.rb @@ -44,7 +44,7 @@ def user_unique_name_temporary_function(username) end def install(only_audit_schema=nil) - schema_restriction = only_audit_schema ? "AND TABLE_schema = '#{only_audit_schema}'" : "" + schema_restriction = only_audit_schema ? "AND table_schema = '#{only_audit_schema}'" : "" execute <<-SQL CREATE OR REPLACE PROCEDURAL LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION #{name}() RETURNS trigger