Class: CreateAuditLogEntries

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/ruby_cms/templates/db/migrate/20260525120000_create_audit_log_entries.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/ruby_cms/templates/db/migrate/20260525120000_create_audit_log_entries.rb', line 6

def change
  create_table :audit_log_entries, if_not_exists: true do |t|
    t.string  :actor_email
    t.bigint  :actor_id
    t.string  :action, null: false
    t.string  :target_type
    t.bigint  :target_id
    t.string  :target_label
    t.string  :summary,      limit: 500
    t.string  :ip,           limit: 64
    t.string  :user_agent,   limit: 500
    RubyCms::MigrationHelpers.json_column(t, :metadata, null: false, default: {})
    t.datetime :created_at,  null: false
  end

  add_index :audit_log_entries, :created_at, order: { created_at: :desc }, if_not_exists: true
  add_index :audit_log_entries, %i[actor_email created_at], if_not_exists: true
  add_index :audit_log_entries, :action, if_not_exists: true
  add_index :audit_log_entries, %i[target_type target_id], if_not_exists: true
end