summaryrefslogtreecommitdiff
path: root/db/migrate/20210818055357_add_unique_commit_design_user_mention_indexes.rb
blob: d9d05f2b737ff97f0251012d5c08ee9170c36b23 (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
# frozen_string_literal: true

class AddUniqueCommitDesignUserMentionIndexes < ActiveRecord::Migration[6.1]
  include Gitlab::Database::MigrationHelpers

  disable_ddl_transaction!

  COMMIT_INDEX_NAME = 'commit_id_and_note_id_index'
  DESIGN_INDEX_NAME = 'design_user_mentions_on_design_id_and_note_id_index'

  COMMIT_UNIQUE_INDEX_NAME = 'commit_user_mentions_on_commit_id_and_note_id_unique_index'
  DESIGN_UNIQUE_INDEX_NAME = 'design_user_mentions_on_design_id_and_note_id_unique_index'

  def up
    add_concurrent_index :commit_user_mentions, [:commit_id, :note_id], unique: true, name: COMMIT_UNIQUE_INDEX_NAME
    add_concurrent_index :design_user_mentions, [:design_id, :note_id], unique: true, name: DESIGN_UNIQUE_INDEX_NAME

    remove_concurrent_index_by_name :commit_user_mentions, COMMIT_INDEX_NAME
    remove_concurrent_index_by_name :design_user_mentions, DESIGN_INDEX_NAME
  end

  def down
    add_concurrent_index :design_user_mentions, [:design_id, :note_id], name: DESIGN_INDEX_NAME
    add_concurrent_index :commit_user_mentions, [:commit_id, :note_id], name: COMMIT_INDEX_NAME

    remove_concurrent_index_by_name :design_user_mentions, DESIGN_UNIQUE_INDEX_NAME
    remove_concurrent_index_by_name :commit_user_mentions, COMMIT_UNIQUE_INDEX_NAME
  end
end