Class: ActiveRecordAuditable::CreateAuditsTableForModelClass

Inherits:
ApplicationService
  • Object
show all
Defined in:
app/services/active_record_auditable/create_audits_table_for_model_class.rb

Instance Method Summary collapse

Instance Method Details

#performObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/active_record_auditable/create_audits_table_for_model_class.rb', line 7

def perform
  create_args = create_table_args || {}

  type_args = {}
  type_args[:type] = id_type if id_type

  ActiveRecord::Migration.new.create_table table_name, **create_args do |t|
    t.references model_class.model_name.param_key.to_sym, null: false, **type_args
    t.json :audited_changes
    t.references :audit_action, foreign_key: true, null: false, **type_args
    t.json :params
    extra_table_actions.call(t) if extra_table_actions
    t.timestamps
  end

  succeed!
end

#table_nameObject



25
26
27
# File 'app/services/active_record_auditable/create_audits_table_for_model_class.rb', line 25

def table_name
  @table_name ||= "#{model_class.table_name.singularize}_audits"
end