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

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

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

  DOWNTIME = false
  TABLE_NAME = :dast_sites
  RELATION_NAME = :dast_site_validations
  FK_NAME = :dast_site_validation_id
  INDEX_NAME = "index_dast_sites_on_#{FK_NAME}"

  disable_ddl_transaction!

  def up
    unless column_exists?(TABLE_NAME, FK_NAME)
      with_lock_retries do
        add_column TABLE_NAME, FK_NAME, :bigint
      end
    end

    add_concurrent_index TABLE_NAME, FK_NAME, name: INDEX_NAME
    add_concurrent_foreign_key TABLE_NAME, RELATION_NAME, column: FK_NAME, on_delete: :nullify
  end

  def down
    remove_foreign_key_if_exists TABLE_NAME, RELATION_NAME
    remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME

    with_lock_retries do
      remove_column TABLE_NAME, FK_NAME
    end
  end
end