-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
142 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Audited | ||
class AuditAssociate < ::ActiveRecord::Base | ||
self.table_name_prefix = "audited_" | ||
|
||
belongs_to :audit | ||
belongs_to :associated, polymorphic: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lib/generators/audited/templates/create_audit_associates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class <%= migration_class_name %> < <%= migration_parent %> | ||
def self.up | ||
create_table :audited_audit_associates, :force => true do |t| | ||
t.column :audit_id, :integer | ||
t.column :associated_id, :integer | ||
t.column :associated_type, :string | ||
end | ||
|
||
execute <<-SQL | ||
INSERT INTO audited_audit_associates (audit_id, associated_id, associated_type) | ||
SELECT id, associated_id, associated_type | ||
FROM audits | ||
SQL | ||
|
||
add_index :audited_audit_associates, :audit_id, :name => 'index_audited_audit_associates_on_audit_id' | ||
add_index :audited_audit_associates, [:associated_type, :associated_id], :name => 'index_audited_audit_associates_on_associated' | ||
|
||
remove_index :audits, name: 'associated_index' | ||
remove_column :audits, :associated_id | ||
remove_column :audits, :associated_type | ||
end | ||
|
||
def self.down | ||
raise ActiveRecord::IrreversibleMigration | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ActiveRecord::Schema.define do | ||
create_table :audits, :force => true do |t| | ||
t.column :auditable_id, :integer | ||
t.column :auditable_type, :string | ||
t.column :associated_id, :integer | ||
t.column :associated_type, :string | ||
t.column :user_id, :integer | ||
t.column :user_type, :string | ||
t.column :username, :string | ||
t.column :action, :string | ||
t.column :audited_changes, :text | ||
t.column :version, :integer, :default => 0 | ||
t.column :comment, :string | ||
t.column :remote_address, :string | ||
t.column :request_uuid, :string | ||
t.column :created_at, :datetime | ||
end | ||
|
||
drop_table :audited_audit_associates if table_exists?(:audited_audit_associates) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters