pg_audit_log 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,12 @@ namespace :pg_audit_log do
|
|
26
26
|
export_development_structure
|
27
27
|
end
|
28
28
|
|
29
|
+
desc "Check all tables that are missing triggers (fails if any are)"
|
30
|
+
task :check => :environment do
|
31
|
+
tables = PgAuditLog::Triggers.tables_without_triggers
|
32
|
+
raise(PgAuditLog::Triggers::MissingTriggers, tables) if tables.any?
|
33
|
+
end
|
34
|
+
|
29
35
|
private
|
30
36
|
|
31
37
|
def export_development_structure
|
@@ -1,10 +1,30 @@
|
|
1
1
|
module PgAuditLog
|
2
2
|
class Triggers < PgAuditLog::ActiveRecord
|
3
|
+
class MissingTriggers < Exception
|
4
|
+
def initialize(tables)
|
5
|
+
@tables = tables
|
6
|
+
end
|
7
|
+
def message
|
8
|
+
"Missing PgAuditLog triggers for the following tables: #{@tables.join(', ')}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
3
12
|
class << self
|
4
13
|
def tables
|
5
14
|
connection.tables - (PgAuditLog::IGNORED_TABLES + [PgAuditLog::Entry.table_name])
|
6
15
|
end
|
7
16
|
|
17
|
+
def tables_without_triggers
|
18
|
+
tables_with_triggers = connection.select_values <<-SQL
|
19
|
+
SELECT tables.relname as table_name
|
20
|
+
FROM pg_trigger triggers, pg_class tables
|
21
|
+
WHERE triggers.tgrelid = tables.oid
|
22
|
+
AND tables.relname !~ '^pg_'
|
23
|
+
AND triggers.tgname LIKE '#{trigger_prefix}%'
|
24
|
+
SQL
|
25
|
+
tables - tables_with_triggers
|
26
|
+
end
|
27
|
+
|
8
28
|
def install
|
9
29
|
tables.each do |table|
|
10
30
|
create_for_table(table)
|
@@ -60,8 +80,12 @@ module PgAuditLog
|
|
60
80
|
execute "ALTER TABLE #{table_name} DISABLE TRIGGER #{trigger_name_for_table(table_name)}"
|
61
81
|
end
|
62
82
|
|
83
|
+
def trigger_prefix
|
84
|
+
"audit_"
|
85
|
+
end
|
86
|
+
|
63
87
|
def trigger_name_for_table(table_name)
|
64
|
-
"
|
88
|
+
"#{trigger_prefix}#{table_name}"
|
65
89
|
end
|
66
90
|
end
|
67
91
|
end
|
data/lib/pg_audit_log/version.rb
CHANGED
data/spec/triggers_spec.rb
CHANGED
@@ -9,6 +9,22 @@ describe PgAuditLog::Triggers do
|
|
9
9
|
table {}
|
10
10
|
end
|
11
11
|
|
12
|
+
with_model :table_without_triggers do
|
13
|
+
table {}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".tables_without_triggers" do
|
17
|
+
before do
|
18
|
+
PgAuditLog::Triggers.create_for_table(TableWithTriggers.table_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return an array of all tables that do not have an audit trigger installed" do
|
22
|
+
PgAuditLog::Triggers.tables_without_triggers.should_not include(TableWithTriggers.table_name)
|
23
|
+
PgAuditLog::Triggers.tables_without_triggers.should include(TableWithoutTriggers.table_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
12
28
|
describe ".install" do
|
13
29
|
it "should work" do
|
14
30
|
->{
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pg_audit_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Case Commons, LLC
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-19 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
requirements: []
|
119
119
|
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 1.6.
|
121
|
+
rubygems_version: 1.6.1
|
122
122
|
signing_key:
|
123
123
|
specification_version: 3
|
124
124
|
summary: postgresql only database-level audit logging of all databases changes
|