summaryrefslogtreecommitdiff
path: root/db/post_migrate/20211031152417_add_indexes_to_issue_stage_events.rb
blob: 73b70ad1e277117c8f30b73b69baf8b7b42dbdef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

class AddIndexesToIssueStageEvents < Gitlab::Database::Migration[1.0]
  include Gitlab::Database::PartitioningMigrationHelpers

  disable_ddl_transaction!

  GROUP_INDEX_NAME = 'index_issue_stage_events_group_duration'
  GROUP_IN_PROGRESS_INDEX_NAME = 'index_issue_stage_events_group_in_progress_duration'
  PROJECT_INDEX_NAME = 'index_issue_stage_events_project_duration'
  PROJECT_IN_PROGRESS_INDEX_NAME = 'index_issue_stage_events_project_in_progress_duration'

  def up
    add_concurrent_partitioned_index :analytics_cycle_analytics_issue_stage_events,
      'stage_event_hash_id, group_id, end_event_timestamp, issue_id, start_event_timestamp',
      where: 'end_event_timestamp IS NOT NULL',
      name: GROUP_INDEX_NAME

    add_concurrent_partitioned_index :analytics_cycle_analytics_issue_stage_events,
      'stage_event_hash_id, project_id, end_event_timestamp, issue_id, start_event_timestamp',
      where: 'end_event_timestamp IS NOT NULL',
      name: PROJECT_INDEX_NAME

    add_concurrent_partitioned_index :analytics_cycle_analytics_issue_stage_events,
      'stage_event_hash_id, group_id, start_event_timestamp, issue_id',
      where: 'end_event_timestamp IS NULL AND state_id = 1',
      name: GROUP_IN_PROGRESS_INDEX_NAME

    add_concurrent_partitioned_index :analytics_cycle_analytics_issue_stage_events,
      'stage_event_hash_id, project_id, start_event_timestamp, issue_id',
      where: 'end_event_timestamp IS NULL AND state_id = 1',
      name: PROJECT_IN_PROGRESS_INDEX_NAME
  end

  def down
    remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_issue_stage_events, GROUP_INDEX_NAME
    remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_issue_stage_events, PROJECT_INDEX_NAME
    remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_issue_stage_events, GROUP_IN_PROGRESS_INDEX_NAME
    remove_concurrent_partitioned_index_by_name :analytics_cycle_analytics_issue_stage_events, PROJECT_IN_PROGRESS_INDEX_NAME
  end
end