Skip to content

Creating migration for new audit events table

Background

As part of &13370 cells migration, we will need to split our audit_events table into 4 new tables:

  1. user_audit_event
  2. project_audit_event
  3. group_audit_event
  4. instance_audit_event

The objective of this issue is to propose the creation of migrations for these new tables

Proposal

Write migration to set up four new tables. We must ensure that IDs in these tables are unique so that the streaming of audit events isn't disrupted.

example migration for user_audit_events:

ActiveRecord::Migration.create_table :user_audit_events do |t|
  t.integer :author_id
  t.integer :user_id
  t.text :details
  t.inet :ip_address
  t.text :author_name
  t.text :entity_path
  t.text :target_details
  t.datetime :created_at
  t.text :target_type
  t.integer :target_id
  t.bigint :id, default: -> { "nextval('audit_event_id_seq')" } 
end

Currently, we have the below indexes on audit_events:

ActiveRecord::Base.connection.indexes(:audit_events)
[
    [0] #<ActiveRecord::ConnectionAdapters::IndexDefinition:0x00000001765fa0b0 @table=:audit_events, @name="analytics_index_audit_events_part_on_created_at_and_author_id", @unique=false, @columns=["created_at", "author_id"], @lengths={}, @orders={}, @opclasses={}, @where=nil, @type=nil, @using=:btree, @comment=nil>,
    [1] #<ActiveRecord::ConnectionAdapters::IndexDefinition:0x00000001765f9930 @table=:audit_events, @name="idx_audit_events_part_on_entity_id_desc_author_id_created_at", @unique=false, @columns=["entity_id", "entity_type", "id", "author_id", "created_at"], @lengths={}, @orders={"id"=>:desc}, @opclasses={}, @where=nil, @type=nil, @using=:btree, @comment=nil>,
    [2] #<ActiveRecord::ConnectionAdapters::IndexDefinition:0x00000001765f8fd0 @table=:audit_events, @name="index_audit_events_on_entity_id_and_entity_type_and_created_at", @unique=false, @columns=["entity_id", "entity_type", "created_at", "id"], @lengths={}, @orders={}, @opclasses={}, @where=nil, @type=nil, @using=:btree, @comment=nil>
]

Create similar indexes for new tables.

Edited by Harsimar Sandhu