Class: CreateAuditLog

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/chrno_audit/templates/migration.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/generators/chrno_audit/templates/migration.rb', line 3

def change
  create_table :audit_log do |t|
    t.string   :auditable_type, :null => false
    t.integer  :auditable_id
    t.string   :initiator_type
    t.integer  :initiator_id
    t.string   :action, :null => false
    t.text     :diff
    t.text     :context
    t.datetime :created_at, :null => false
  end

  add_index :audit_log, [ :auditable_type, :auditable_id ]
  add_index :audit_log, [ :initiator_type, :initiator_id ]
  add_index :audit_log, :action
  add_index :audit_log, :created_at, :order => { :created_at => :desc }
end