pg_audit_log 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format nested
2
+ --color
data/README.rdoc CHANGED
@@ -9,6 +9,8 @@ Comes with specs for your project and a rake task to generate the reverse SQL to
9
9
 
10
10
  All SQL INSERTs, UPDATEs, and DELETEs will be captured. Record columns that do not change do not generate an audit log entry.
11
11
 
12
+ Compatible with Rails 3.0.x and 3.1.x
13
+
12
14
  == INSTALL
13
15
 
14
16
  === Enable custom variables in your postgresql instance
@@ -0,0 +1,64 @@
1
+ require "active_record/connection_adapters/postgresql_adapter"
2
+
3
+ # Did not want to reopen the class but sending an include seemingly is not working.
4
+ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
5
+ def generate_auditing_sql(sql)
6
+ current_user = Thread.current[:current_user]
7
+ user_unique_name = current_user.try(:unique_name) || "UNKNOWN"
8
+
9
+ log_user_id = %[SET audit.user_id = #{current_user.try(:id) || "-1"}]
10
+ log_user_unique_name = %[SET audit.user_unique_name = "#{user_unique_name}"]
11
+ { :user_id => log_user_id, :unique_name => log_user_unique_name, :sql => sql }
12
+ end
13
+
14
+ def exec_query_with_auditing(sql, name = 'SQL', binds = [])
15
+ audited_sql = generate_auditing_sql(sql)
16
+ log(audited_sql.values.join("; "), name, binds) do
17
+ exec_no_cache(audited_sql[:user_id], binds)
18
+ exec_no_cache(audited_sql[:unique_name], binds)
19
+ result = binds.empty? ? exec_no_cache(sql, binds) :
20
+ exec_cache(sql, binds)
21
+
22
+ ret = ActiveRecord::Result.new(result.fields, result_as_array(result))
23
+ result.clear
24
+ return ret
25
+ end
26
+ end
27
+ alias_method_chain :exec_query, :auditing
28
+
29
+ def execute_with_auditing(sql, name = nil)
30
+ log(generate_auditing_sql(sql), name) do
31
+ @connection.async_exec(sql)
32
+ end
33
+ end
34
+ alias_method_chain :execute, :auditing
35
+
36
+ def begin_db_transaction
37
+ execute_without_auditing "BEGIN"
38
+ end
39
+
40
+ # Commits a transaction.
41
+ def commit_db_transaction
42
+ execute_without_auditing "COMMIT"
43
+ end
44
+
45
+ # Aborts a transaction.
46
+ def rollback_db_transaction
47
+ execute_without_auditing "ROLLBACK"
48
+ end
49
+
50
+ def create_savepoint
51
+ execute_without_auditing("SAVEPOINT #{current_savepoint_name}")
52
+ end
53
+
54
+ def rollback_to_savepoint
55
+ execute_without_auditing("ROLLBACK TO SAVEPOINT #{current_savepoint_name}")
56
+ end
57
+
58
+ def release_savepoint
59
+ execute_without_auditing("RELEASE SAVEPOINT #{current_savepoint_name}")
60
+ end
61
+
62
+ end
63
+
64
+
@@ -1,3 +1,3 @@
1
1
  module PgAuditLog
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/pg_audit_log.rb CHANGED
@@ -4,7 +4,17 @@ end
4
4
 
5
5
  require "active_record"
6
6
  require "pg_audit_log/version"
7
- require "pg_audit_log/extensions/postgresql_adapter.rb"
7
+
8
+ case ::ActiveRecord::VERSION::MAJOR
9
+ when 3
10
+ if ::ActiveRecord::VERSION::MINOR == 0
11
+ require "pg_audit_log/extensions/3.0/postgresql_adapter.rb"
12
+ else
13
+ require "pg_audit_log/extensions/3.1/postgresql_adapter.rb"
14
+ end
15
+ else
16
+ raise "ActiveRecord #{::ActiveRecord::VERSION::MAJOR}.x unsupported!"
17
+ end
8
18
  require "pg_audit_log/active_record"
9
19
  require "pg_audit_log/entry"
10
20
  require "pg_audit_log/function"
@@ -55,7 +55,7 @@ describe PgAuditLog do
55
55
 
56
56
  context "when a user is present" do
57
57
  before do
58
- Thread.current[:current_user] = stub(:id => 1, :unique_name => "my current user")
58
+ Thread.current[:current_user] = stub("User", :id => 1, :unique_name => "my current user")
59
59
  AuditedModel.create!
60
60
  end
61
61
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_audit_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-19 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2011-09-15 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rails
17
- requirement: &2165611780 !ruby/object:Gem::Requirement
16
+ requirement: &2152957860 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: 3.0.0
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2165611780
24
+ version_requirements: *2152957860
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: pg
28
- requirement: &2165611280 !ruby/object:Gem::Requirement
27
+ requirement: &2152957060 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: 0.9.0
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: *2165611280
35
+ version_requirements: *2152957060
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: rspec-rails
39
- requirement: &2165610900 !ruby/object:Gem::Requirement
38
+ requirement: &2152956560 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '0'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2165610900
46
+ version_requirements: *2152956560
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: with_model
50
- requirement: &2165610360 !ruby/object:Gem::Requirement
49
+ requirement: &2152955700 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,7 +54,7 @@ dependencies:
55
54
  version: 0.1.3
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *2165610360
57
+ version_requirements: *2152955700
59
58
  description: A completely transparent audit logging component for your application
60
59
  using a stored procedure and triggers. Comes with specs for your project and a rake
61
60
  task to generate the reverse SQL to undo changes logged
@@ -66,6 +65,7 @@ extensions: []
66
65
  extra_rdoc_files: []
67
66
  files:
68
67
  - .gitignore
68
+ - .rspec
69
69
  - .rvmrc
70
70
  - Gemfile
71
71
  - LICENSE
@@ -81,7 +81,8 @@ files:
81
81
  - lib/pg_audit_log.rb
82
82
  - lib/pg_audit_log/active_record.rb
83
83
  - lib/pg_audit_log/entry.rb
84
- - lib/pg_audit_log/extensions/postgresql_adapter.rb
84
+ - lib/pg_audit_log/extensions/3.0/postgresql_adapter.rb
85
+ - lib/pg_audit_log/extensions/3.1/postgresql_adapter.rb
85
86
  - lib/pg_audit_log/function.rb
86
87
  - lib/pg_audit_log/triggers.rb
87
88
  - lib/pg_audit_log/version.rb
@@ -92,7 +93,6 @@ files:
92
93
  - spec/pg_audit_log_spec.rb
93
94
  - spec/spec_helper.rb
94
95
  - spec/triggers_spec.rb
95
- has_rdoc: true
96
96
  homepage: https://github.com/Casecommons/pg_audit_log
97
97
  licenses: []
98
98
  post_install_message:
@@ -105,15 +105,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  - - ! '>='
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
+ segments:
109
+ - 0
110
+ hash: -1882203804259823280
108
111
  required_rubygems_version: !ruby/object:Gem::Requirement
109
112
  none: false
110
113
  requirements:
111
114
  - - ! '>='
112
115
  - !ruby/object:Gem::Version
113
116
  version: '0'
117
+ segments:
118
+ - 0
119
+ hash: -1882203804259823280
114
120
  requirements: []
115
121
  rubyforge_project:
116
- rubygems_version: 1.6.2
122
+ rubygems_version: 1.8.10
117
123
  signing_key:
118
124
  specification_version: 3
119
125
  summary: postgresql only database-level audit logging of all databases changes