Prepare temporary index for BackfillEventsTargetTypeForProjects
See 'target_type' parameter for Events API is nil f... (&19098 - closed) for context
Currently, project events are created without a set target_type and target_id. This is causing a problem with our Events RESP API as the target_type filter always gives an empty result for project.
After Set `events.target_type` to `project` when crea... (#565786 - closed) has been completed. We now need to backfill the existing records.
Implementation Guide
- Create a temporary index to efficiently run the backfill migration:
# frozen_string_literal: true
class PrepareTmpIdxEventsWhereProjectTargetTypeMissing < Gitlab::Database::Migration[2.3]
milestone '18.4'
INDEX_NAME = :tmp_idx_events_where_project_target_type_missing
PROJECT_ACTIONS = [1, 5, 8, 9, 11].freeze # Defined in `/app/models/event.rb`
def up
prepare_async_index(
:events, :id,
where: "target_type IS NULL AND action IN (#{PROJECT_ACTIONS.join(',')}) AND project_id IS NOT NULL",
name: INDEX_NAME
)
end
def down
remove_concurrent_index_by_name :events, INDEX_NAME
end
end
This index will be used for Create `BackfillEventsTargetTypeForProjects` ba... (#565788 - closed)
Edited by Shane Maglangit