Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20221110150942_add_project_id_lower_name_index_remove_old_index.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dfff2f896103d73bfe29832f8a08511c7f54102e (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
# frozen_string_literal: true

class AddProjectIdLowerNameIndexRemoveOldIndex < Gitlab::Database::Migration[2.0]
  INDEX_NAME = 'index_im_timeline_event_tags_name_project_id'
  NEW_INDEX_NAME = 'index_im_timeline_event_tags_on_lower_name_and_project_id'

  disable_ddl_transaction!

  def up
    # Add new index
    add_concurrent_index :incident_management_timeline_event_tags, 'project_id, LOWER(name)',
      unique: true, name: NEW_INDEX_NAME

    # Remove old index
    remove_concurrent_index_by_name :incident_management_timeline_event_tags, INDEX_NAME
  end

  def down
    # Add old index
    add_concurrent_index :incident_management_timeline_event_tags, [:project_id, :name],
      unique: true, name: INDEX_NAME

    # Remove new index
    remove_concurrent_index_by_name :incident_management_timeline_event_tags, NEW_INDEX_NAME
  end
end