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

20201123161611_add_provisioned_by_group_to_user_details.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e4d0e8450936966b0701a439de2de577a95560f (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 AddProvisionedByGroupToUserDetails < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  INDEX_NAME = 'index_user_details_on_provisioned_by_group_id'

  disable_ddl_transaction!

  def up
    unless column_exists?(:user_details, :provisioned_by_group_id)
      with_lock_retries { add_column(:user_details, :provisioned_by_group_id, :integer, limit: 8) }
    end

    add_concurrent_index :user_details, :provisioned_by_group_id, name: INDEX_NAME
    add_concurrent_foreign_key :user_details, :namespaces, column: :provisioned_by_group_id, on_delete: :nullify
  end

  def down
    with_lock_retries { remove_foreign_key_without_error :user_details, column: :provisioned_by_group_id }

    remove_concurrent_index_by_name :user_details, INDEX_NAME

    if column_exists?(:user_details, :provisioned_by_group_id)
      with_lock_retries { remove_column(:user_details, :provisioned_by_group_id) }
    end
  end
end