notifiably_audited 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +17 -0
- data/Appraisals +11 -0
- data/CHANGELOG +34 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +234 -0
- data/Rakefile +24 -0
- data/audited-activerecord.gemspec +21 -0
- data/audited-mongo_mapper.gemspec +21 -0
- data/audited.gemspec +27 -0
- data/gemfiles/rails30.gemfile +7 -0
- data/gemfiles/rails31.gemfile +7 -0
- data/gemfiles/rails32.gemfile +7 -0
- data/lib/audited/audit.rb +115 -0
- data/lib/audited/auditor.rb +449 -0
- data/lib/audited/rspec_matchers.rb +173 -0
- data/lib/audited/sweeper.rb +51 -0
- data/lib/audited.rb +15 -0
- data/lib/notifiably_audited/version.rb +3 -0
- data/lib/notifiably_audited.rb +15 -0
- data/notifiably_audited.gemspec +23 -0
- data/spec/audited_spec_helpers.rb +31 -0
- data/spec/rails_app/config/application.rb +5 -0
- data/spec/rails_app/config/database.yml +24 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/development.rb +19 -0
- data/spec/rails_app/config/environments/production.rb +33 -0
- data/spec/rails_app/config/environments/test.rb +33 -0
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_app/config/initializers/inflections.rb +2 -0
- data/spec/rails_app/config/initializers/secret_token.rb +2 -0
- data/spec/rails_app/config/routes.rb +6 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/active_record/models.rb +84 -0
- data/spec/support/active_record/schema.rb +54 -0
- data/spec/support/mongo_mapper/connection.rb +4 -0
- data/spec/support/mongo_mapper/models.rb +210 -0
- data/test/db/version_1.rb +17 -0
- data/test/db/version_2.rb +18 -0
- data/test/db/version_3.rb +19 -0
- data/test/db/version_4.rb +20 -0
- data/test/db/version_5.rb +18 -0
- data/test/install_generator_test.rb +17 -0
- data/test/test_helper.rb +19 -0
- data/test/upgrade_generator_test.rb +65 -0
- metadata +159 -31
- data/lib/audited/adapters/active_record/audit.rb +0 -69
- data/lib/audited/adapters/active_record.rb +0 -15
- data/lib/audited-activerecord.rb +0 -2
- data/lib/generators/audited/install_generator.rb +0 -28
- data/lib/generators/audited/templates/add_association_to_audits.rb +0 -11
- data/lib/generators/audited/templates/add_comment_to_audits.rb +0 -9
- data/lib/generators/audited/templates/add_remote_address_to_audits.rb +0 -10
- data/lib/generators/audited/templates/install.rb +0 -35
- data/lib/generators/audited/templates/rename_association_to_associated.rb +0 -23
- data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +0 -9
- data/lib/generators/audited/templates/rename_parent_to_association.rb +0 -11
- data/lib/generators/audited/upgrade_generator.rb +0 -63
@@ -0,0 +1,18 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
create_table :audits, :force => true do |t|
|
3
|
+
t.column :auditable_id, :integer
|
4
|
+
t.column :auditable_type, :string
|
5
|
+
t.column :user_id, :integer
|
6
|
+
t.column :user_type, :string
|
7
|
+
t.column :username, :string
|
8
|
+
t.column :action, :string
|
9
|
+
t.column :audited_changes, :text
|
10
|
+
t.column :version, :integer, :default => 0
|
11
|
+
t.column :comment, :string
|
12
|
+
t.column :created_at, :datetime
|
13
|
+
t.column :remote_address, :string
|
14
|
+
t.column :association_id, :integer
|
15
|
+
t.column :association_type, :string
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'generators/audited/install_generator'
|
4
|
+
|
5
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
6
|
+
destination File.expand_path('../../tmp', __FILE__)
|
7
|
+
setup :prepare_destination
|
8
|
+
tests Audited::Generators::InstallGenerator
|
9
|
+
|
10
|
+
test "should generate a migration" do
|
11
|
+
run_generator %w(install)
|
12
|
+
|
13
|
+
assert_migration "db/migrate/install_audited.rb" do |content|
|
14
|
+
assert_match /class InstallAudited/, content
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
ENV['RAILS_ENV'] = 'test'
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)
|
4
|
+
|
5
|
+
require File.expand_path('../../spec/rails_app/config/environment', __FILE__)
|
6
|
+
require 'rails/test_help'
|
7
|
+
|
8
|
+
require 'audited'
|
9
|
+
|
10
|
+
class ActiveSupport::TestCase
|
11
|
+
|
12
|
+
setup do
|
13
|
+
ActiveRecord::Migration.verbose = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_schema( version )
|
17
|
+
load File.dirname(__FILE__) + "/db/version_#{version}.rb"
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'generators/audited/upgrade_generator'
|
4
|
+
|
5
|
+
class UpgradeGeneratorTest < Rails::Generators::TestCase
|
6
|
+
destination File.expand_path('../../tmp', __FILE__)
|
7
|
+
setup :prepare_destination
|
8
|
+
tests Audited::Generators::UpgradeGenerator
|
9
|
+
|
10
|
+
test "should add 'comment' to audits table" do
|
11
|
+
load_schema 1
|
12
|
+
|
13
|
+
run_generator %w(upgrade)
|
14
|
+
|
15
|
+
assert_migration "db/migrate/add_comment_to_audits.rb" do |content|
|
16
|
+
assert_match /add_column :audits, :comment, :string/, content
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_migration "db/migrate/rename_changes_to_audited_changes.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
test "should rename 'changes' to 'audited_changes'" do
|
23
|
+
load_schema 2
|
24
|
+
|
25
|
+
run_generator %w(upgrade)
|
26
|
+
|
27
|
+
assert_no_migration "db/migrate/add_comment_to_audits.rb"
|
28
|
+
|
29
|
+
assert_migration "db/migrate/rename_changes_to_audited_changes.rb" do |content|
|
30
|
+
assert_match /rename_column :audits, :changes, :audited_changes/, content
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
test "should add a 'remote_address' to audits table" do
|
35
|
+
load_schema 3
|
36
|
+
|
37
|
+
run_generator %w(upgrade)
|
38
|
+
|
39
|
+
assert_migration "db/migrate/add_remote_address_to_audits.rb" do |content|
|
40
|
+
assert_match /add_column :audits, :remote_address, :string/, content
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test "should add 'association_id' and 'association_type' to audits table" do
|
45
|
+
load_schema 4
|
46
|
+
|
47
|
+
run_generator %w(upgrade)
|
48
|
+
|
49
|
+
assert_migration "db/migrate/add_association_to_audits.rb" do |content|
|
50
|
+
assert_match /add_column :audits, :association_id, :integer/, content
|
51
|
+
assert_match /add_column :audits, :association_type, :string/, content
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test "should rename 'association_id' to 'associated_id' and 'association_type' to 'associated_type'" do
|
56
|
+
load_schema 5
|
57
|
+
|
58
|
+
run_generator %w(upgrade)
|
59
|
+
|
60
|
+
assert_migration "db/migrate/rename_association_to_associated.rb" do |content|
|
61
|
+
assert_match /rename_column :audits, :association_id, :associated_id/, content
|
62
|
+
assert_match /rename_column :audits, :association_type, :associated_type/, content
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,68 +1,180 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifiably_audited
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
- Kenneth Kalmer
|
9
|
-
- Daniel Morrison
|
10
|
-
- Brian Ryckbost
|
11
|
-
- Steve Richert
|
12
|
-
- Ryan Glover
|
7
|
+
- senthil kumar
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
date: 2014-03-19 00:00:00.000000000 Z
|
17
12
|
dependencies:
|
18
13
|
- !ruby/object:Gem::Dependency
|
19
|
-
name:
|
14
|
+
name: activerecord
|
20
15
|
requirement: !ruby/object:Gem::Requirement
|
21
16
|
requirements:
|
22
|
-
- -
|
17
|
+
- - ~>
|
23
18
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
25
|
-
type: :
|
19
|
+
version: '3.0'
|
20
|
+
type: :development
|
26
21
|
prerelease: false
|
27
22
|
version_requirements: !ruby/object:Gem::Requirement
|
28
23
|
requirements:
|
29
|
-
- -
|
24
|
+
- - ~>
|
30
25
|
- !ruby/object:Gem::Version
|
31
|
-
version:
|
26
|
+
version: '3.0'
|
32
27
|
- !ruby/object:Gem::Dependency
|
33
|
-
name:
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bson_ext
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mongo_mapper
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.11'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.11'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
34
71
|
requirement: !ruby/object:Gem::Requirement
|
35
72
|
requirements:
|
36
73
|
- - ~>
|
37
74
|
- !ruby/object:Gem::Version
|
38
75
|
version: '3.0'
|
39
|
-
type: :
|
76
|
+
type: :development
|
40
77
|
prerelease: false
|
41
78
|
version_requirements: !ruby/object:Gem::Requirement
|
42
79
|
requirements:
|
43
80
|
- - ~>
|
44
81
|
- !ruby/object:Gem::Version
|
45
82
|
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: private_pub
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
46
125
|
description: Log all changes to your ActiveRecord models
|
47
|
-
email:
|
126
|
+
email: senthilkumar.hce@gmail.com
|
48
127
|
executables: []
|
49
128
|
extensions: []
|
50
129
|
extra_rdoc_files: []
|
51
130
|
files:
|
131
|
+
- .gitignore
|
132
|
+
- Appraisals
|
133
|
+
- CHANGELOG
|
134
|
+
- Gemfile
|
52
135
|
- LICENSE
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
- lib/
|
63
|
-
- lib/
|
64
|
-
- lib/
|
65
|
-
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- audited-activerecord.gemspec
|
140
|
+
- audited-mongo_mapper.gemspec
|
141
|
+
- audited.gemspec
|
142
|
+
- gemfiles/rails30.gemfile
|
143
|
+
- gemfiles/rails31.gemfile
|
144
|
+
- gemfiles/rails32.gemfile
|
145
|
+
- lib/audited.rb
|
146
|
+
- lib/audited/audit.rb
|
147
|
+
- lib/audited/auditor.rb
|
148
|
+
- lib/audited/rspec_matchers.rb
|
149
|
+
- lib/audited/sweeper.rb
|
150
|
+
- lib/notifiably_audited.rb
|
151
|
+
- lib/notifiably_audited/version.rb
|
152
|
+
- notifiably_audited.gemspec
|
153
|
+
- spec/audited_spec_helpers.rb
|
154
|
+
- spec/rails_app/config/application.rb
|
155
|
+
- spec/rails_app/config/database.yml
|
156
|
+
- spec/rails_app/config/environment.rb
|
157
|
+
- spec/rails_app/config/environments/development.rb
|
158
|
+
- spec/rails_app/config/environments/production.rb
|
159
|
+
- spec/rails_app/config/environments/test.rb
|
160
|
+
- spec/rails_app/config/initializers/backtrace_silencers.rb
|
161
|
+
- spec/rails_app/config/initializers/inflections.rb
|
162
|
+
- spec/rails_app/config/initializers/secret_token.rb
|
163
|
+
- spec/rails_app/config/routes.rb
|
164
|
+
- spec/spec_helper.rb
|
165
|
+
- spec/support/active_record/models.rb
|
166
|
+
- spec/support/active_record/schema.rb
|
167
|
+
- spec/support/mongo_mapper/connection.rb
|
168
|
+
- spec/support/mongo_mapper/models.rb
|
169
|
+
- test/db/version_1.rb
|
170
|
+
- test/db/version_2.rb
|
171
|
+
- test/db/version_3.rb
|
172
|
+
- test/db/version_4.rb
|
173
|
+
- test/db/version_5.rb
|
174
|
+
- test/install_generator_test.rb
|
175
|
+
- test/test_helper.rb
|
176
|
+
- test/upgrade_generator_test.rb
|
177
|
+
homepage: ''
|
66
178
|
licenses:
|
67
179
|
- MIT
|
68
180
|
metadata: {}
|
@@ -85,6 +197,22 @@ rubyforge_project:
|
|
85
197
|
rubygems_version: 2.2.2
|
86
198
|
signing_key:
|
87
199
|
specification_version: 4
|
88
|
-
summary:
|
89
|
-
test_files:
|
200
|
+
summary: ''
|
201
|
+
test_files:
|
202
|
+
- spec/audited_spec_helpers.rb
|
203
|
+
- spec/rails_app/config/application.rb
|
204
|
+
- spec/rails_app/config/database.yml
|
205
|
+
- spec/rails_app/config/environment.rb
|
206
|
+
- spec/rails_app/config/environments/development.rb
|
207
|
+
- spec/rails_app/config/environments/production.rb
|
208
|
+
- spec/rails_app/config/environments/test.rb
|
209
|
+
- spec/rails_app/config/initializers/backtrace_silencers.rb
|
210
|
+
- spec/rails_app/config/initializers/inflections.rb
|
211
|
+
- spec/rails_app/config/initializers/secret_token.rb
|
212
|
+
- spec/rails_app/config/routes.rb
|
213
|
+
- spec/spec_helper.rb
|
214
|
+
- spec/support/active_record/models.rb
|
215
|
+
- spec/support/active_record/schema.rb
|
216
|
+
- spec/support/mongo_mapper/connection.rb
|
217
|
+
- spec/support/mongo_mapper/models.rb
|
90
218
|
has_rdoc:
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'audited/audit'
|
3
|
-
|
4
|
-
module Audited
|
5
|
-
module Adapters
|
6
|
-
module ActiveRecord
|
7
|
-
# Audit saves the changes to ActiveRecord models. It has the following attributes:
|
8
|
-
#
|
9
|
-
# * <tt>auditable</tt>: the ActiveRecord model that was changed
|
10
|
-
# * <tt>user</tt>: the user that performed the change; a string or an ActiveRecord model
|
11
|
-
# * <tt>action</tt>: one of create, update, or delete
|
12
|
-
# * <tt>audited_changes</tt>: a serialized hash of all the changes
|
13
|
-
# * <tt>comment</tt>: a comment set with the audit
|
14
|
-
# * <tt>created_at</tt>: Time that the change was performed
|
15
|
-
#
|
16
|
-
class Audit < ::ActiveRecord::Base
|
17
|
-
include Audited::Audit
|
18
|
-
|
19
|
-
|
20
|
-
serialize :audited_changes
|
21
|
-
|
22
|
-
default_scope order(:version)
|
23
|
-
scope :descending, reorder("version DESC")
|
24
|
-
scope :creates, :conditions => {:action => 'create'}
|
25
|
-
scope :updates, :conditions => {:action => 'update'}
|
26
|
-
scope :destroys, :conditions => {:action => 'destroy'}
|
27
|
-
|
28
|
-
scope :up_until, lambda {|date_or_time| where("created_at <= ?", date_or_time) }
|
29
|
-
scope :from_version, lambda {|version| where(['version >= ?', version]) }
|
30
|
-
scope :to_version, lambda {|version| where(['version <= ?', version]) }
|
31
|
-
|
32
|
-
# Return all audits older than the current one.
|
33
|
-
def ancestors
|
34
|
-
self.class.where(['auditable_id = ? and auditable_type = ? and version <= ?',
|
35
|
-
auditable_id, auditable_type, version])
|
36
|
-
end
|
37
|
-
|
38
|
-
# Allows user to be set to either a string or an ActiveRecord object
|
39
|
-
# @private
|
40
|
-
def user_as_string=(user)
|
41
|
-
# reset both either way
|
42
|
-
self.user_as_model = self.username = nil
|
43
|
-
user.is_a?(::ActiveRecord::Base) ?
|
44
|
-
self.user_as_model = user :
|
45
|
-
self.username = user
|
46
|
-
end
|
47
|
-
alias_method :user_as_model=, :user=
|
48
|
-
alias_method :user=, :user_as_string=
|
49
|
-
|
50
|
-
# @private
|
51
|
-
def user_as_string
|
52
|
-
self.user_as_model || self.username
|
53
|
-
end
|
54
|
-
alias_method :user_as_model, :user
|
55
|
-
alias_method :user, :user_as_string
|
56
|
-
|
57
|
-
private
|
58
|
-
def set_version_number
|
59
|
-
max = self.class.maximum(:version,
|
60
|
-
:conditions => {
|
61
|
-
:auditable_id => auditable_id,
|
62
|
-
:auditable_type => auditable_type
|
63
|
-
}) || 0
|
64
|
-
self.version = max + 1
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require 'audited/auditor'
|
3
|
-
require 'audited/adapters/active_record/audit'
|
4
|
-
|
5
|
-
module Audited::Auditor::ClassMethods
|
6
|
-
def default_ignored_attributes
|
7
|
-
[self.primary_key, inheritance_column]
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
::ActiveRecord::Base.send :include, Audited::Auditor
|
12
|
-
|
13
|
-
Audited.audit_class = Audited::Adapters::ActiveRecord::Audit
|
14
|
-
|
15
|
-
require 'audited/sweeper'
|
data/lib/audited-activerecord.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/migration'
|
3
|
-
require 'active_record'
|
4
|
-
require 'rails/generators/active_record'
|
5
|
-
|
6
|
-
module Audited
|
7
|
-
module Generators
|
8
|
-
class InstallGenerator < Rails::Generators::Base
|
9
|
-
include Rails::Generators::Migration
|
10
|
-
|
11
|
-
source_root File.expand_path("../templates", __FILE__)
|
12
|
-
|
13
|
-
# Implement the required interface for Rails::Generators::Migration.
|
14
|
-
def self.next_migration_number(dirname) #:nodoc:
|
15
|
-
next_migration_number = current_migration_number(dirname) + 1
|
16
|
-
if ActiveRecord::Base.timestamped_migrations
|
17
|
-
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
18
|
-
else
|
19
|
-
"%.3d" % next_migration_number
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def copy_migration
|
24
|
-
migration_template 'install.rb', 'db/migrate/install_audited.rb'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
add_column :audits, :association_id, :integer
|
4
|
-
add_column :audits, :association_type, :string
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.down
|
8
|
-
remove_column :audits, :association_type
|
9
|
-
remove_column :audits, :association_id
|
10
|
-
end
|
11
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :audits, :force => true do |t|
|
4
|
-
t.column :auditable_id, :integer
|
5
|
-
t.column :auditable_type, :string
|
6
|
-
t.column :associated_id, :integer
|
7
|
-
t.column :associated_type, :string
|
8
|
-
t.column :user_id, :integer
|
9
|
-
t.column :user_type, :string
|
10
|
-
t.column :username, :string
|
11
|
-
t.column :action, :string
|
12
|
-
t.column :audited_changes, :text
|
13
|
-
t.column :version, :integer, :default => 0
|
14
|
-
t.column :comment, :string
|
15
|
-
t.column :remote_address, :string
|
16
|
-
# added by senthil
|
17
|
-
#========
|
18
|
-
t.column :meta, :string
|
19
|
-
t.column :receiver_id, :integer
|
20
|
-
t.column :checked, :boolean
|
21
|
-
t.column :title, :string
|
22
|
-
#========
|
23
|
-
t.column :created_at, :datetime
|
24
|
-
end
|
25
|
-
|
26
|
-
add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
|
27
|
-
add_index :audits, [:associated_id, :associated_type], :name => 'associated_index'
|
28
|
-
add_index :audits, [:user_id, :user_type], :name => 'user_index'
|
29
|
-
add_index :audits, :created_at
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.down
|
33
|
-
drop_table :audits
|
34
|
-
end
|
35
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
if index_exists? :audits, [:association_id, :association_type], :name => 'association_index'
|
4
|
-
remove_index :audits, :name => 'association_index'
|
5
|
-
end
|
6
|
-
|
7
|
-
rename_column :audits, :association_id, :associated_id
|
8
|
-
rename_column :audits, :association_type, :associated_type
|
9
|
-
|
10
|
-
add_index :audits, [:associated_id, :associated_type], :name => 'associated_index'
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.down
|
14
|
-
if index_exists? :audits, [:associated_id, :associated_type], :name => 'associated_index'
|
15
|
-
remove_index :audits, :name => 'associated_index'
|
16
|
-
end
|
17
|
-
|
18
|
-
rename_column :audits, :associated_type, :association_type
|
19
|
-
rename_column :audits, :associated_id, :association_id
|
20
|
-
|
21
|
-
add_index :audits, [:association_id, :association_type], :name => 'association_index'
|
22
|
-
end
|
23
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
rename_column :audits, :auditable_parent_id, :association_id
|
4
|
-
rename_column :audits, :auditable_parent_type, :association_type
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.down
|
8
|
-
rename_column :audits, :association_type, :auditable_parent_type
|
9
|
-
rename_column :audits, :association_id, :auditable_parent_id
|
10
|
-
end
|
11
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/migration'
|
3
|
-
require 'active_record'
|
4
|
-
require 'rails/generators/active_record'
|
5
|
-
|
6
|
-
module Audited
|
7
|
-
module Generators
|
8
|
-
class UpgradeGenerator < Rails::Generators::Base
|
9
|
-
include Rails::Generators::Migration
|
10
|
-
|
11
|
-
source_root File.expand_path("../templates", __FILE__)
|
12
|
-
|
13
|
-
# Implement the required interface for Rails::Generators::Migration.
|
14
|
-
def self.next_migration_number(dirname) #:nodoc:
|
15
|
-
next_migration_number = current_migration_number(dirname) + 1
|
16
|
-
if ActiveRecord::Base.timestamped_migrations
|
17
|
-
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
18
|
-
else
|
19
|
-
"%.3d" % next_migration_number
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def copy_templates
|
24
|
-
migrations_to_be_applied do |m|
|
25
|
-
migration_template "#{m}.rb", "db/migrate/#{m}.rb"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def migrations_to_be_applied
|
32
|
-
Audited::Adapters::ActiveRecord::Audit.reset_column_information
|
33
|
-
columns = Audited::Adapters::ActiveRecord::Audit.columns.map(&:name)
|
34
|
-
|
35
|
-
unless columns.include?( 'comment' )
|
36
|
-
yield :add_comment_to_audits
|
37
|
-
end
|
38
|
-
|
39
|
-
if columns.include?( 'changes' )
|
40
|
-
yield :rename_changes_to_audited_changes
|
41
|
-
end
|
42
|
-
|
43
|
-
unless columns.include?( 'remote_address' )
|
44
|
-
yield :add_remote_address_to_audits
|
45
|
-
end
|
46
|
-
|
47
|
-
unless columns.include?( 'association_id' )
|
48
|
-
if columns.include?('auditable_parent_id')
|
49
|
-
yield :rename_parent_to_association
|
50
|
-
else
|
51
|
-
unless columns.include?( 'associated_id' )
|
52
|
-
yield :add_association_to_audits
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
if columns.include?( 'association_id' )
|
58
|
-
yield :rename_association_to_associated
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|