summaryrefslogtreecommitdiff
path: root/db/migrate/20201005092753_add_framework_id_to_project_framework_settings.rb
blob: f9ac12dcfd2de461fe52168daf4dd1bbc5fda380 (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
# frozen_string_literal: true

class AddFrameworkIdToProjectFrameworkSettings < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    unless column_exists?(:project_compliance_framework_settings, :framework_id)
      with_lock_retries do
        add_column(:project_compliance_framework_settings, :framework_id, :bigint)
      end
    end

    add_concurrent_index(:project_compliance_framework_settings, :framework_id)

    add_concurrent_foreign_key(
      :project_compliance_framework_settings,
      :compliance_management_frameworks,
      column: :framework_id,
      on_delete: :cascade
    )
  end

  def down
    remove_foreign_key_if_exists(:project_compliance_framework_settings, :compliance_management_frameworks, column: :framework_id)

    with_lock_retries do
      remove_column(:project_compliance_framework_settings, :framework_id)
    end
  end
end