Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/pg_audit_log/function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 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;
Expand Down