summaryrefslogtreecommitdiff
path: root/db/migrate/20221202202351_remove_index_i_ci_job_token_project_scope_links_on_source_and_target_project.rb
blob: 81a636739b48f2d64bd649d721f69c47deca1a40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true
class RemoveIndexICiJobTokenProjectScopeLinksOnSourceAndTargetProject < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!

  TABLE_NAME = 'ci_job_token_project_scope_links'
  OLD_INDEX_NAME = 'i_ci_job_token_project_scope_links_on_source_and_target_project'
  NEW_INDEX_NAME = 'ci_job_token_scope_links_source_and_target_project_direction'
  NEW_INDEX_COL = %w[source_project_id target_project_id direction]

  def up
    add_concurrent_index(
      TABLE_NAME,
      NEW_INDEX_COL,
      name: NEW_INDEX_NAME,
      unique: true
    )
    remove_concurrent_index_by_name(TABLE_NAME, OLD_INDEX_NAME)
  end

  def down
    # noop: as we can have duplicate records once the unique index is removed
  end
end