summaryrefslogtreecommitdiff
path: root/db/migrate/20210818061156_remove_project_profile_compound_index_from_dast_profile_schedules.rb
blob: b50947a0a999428ab10008f2f3f14dd54268535a (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
# frozen_string_literal: true

# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

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

  TABLE = :dast_profile_schedules
  INDEX_NAME = 'index_dast_profile_schedules_on_project_id_and_dast_profile_id'
  # We disable these cops here because changing this index is safe. The table does not
  # have any data in it as it's behind a feature flag.
  # rubocop: disable Migration/AddIndex
  # rubocop: disable Migration/RemoveIndex
  def up
    execute('DELETE FROM dast_profile_schedules')

    if index_exists_by_name?(TABLE, INDEX_NAME)
      remove_index TABLE, %i[project_id dast_profile_id], name: INDEX_NAME
    end
  end

  def down
    execute('DELETE FROM dast_profile_schedules')

    unless index_exists_by_name?(TABLE, INDEX_NAME)
      add_index TABLE, %i[project_id dast_profile_id], unique: true, name: INDEX_NAME
    end
  end
end