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

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

class RemoveNamespacesTmpProjectIdColumn < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!

  INDEX_NAME = 'tmp_index_on_tmp_project_id_on_namespaces'

  def up
    with_lock_retries do
      remove_column :namespaces, :tmp_project_id if column_exists?(:namespaces, :tmp_project_id)
    end
  end

  def down
    unless column_exists?(:namespaces, :tmp_project_id)
      with_lock_retries do
        # rubocop:disable Migration/AddColumnsToWideTables
        add_column :namespaces, :tmp_project_id, :integer
        # rubocop:enable Migration/AddColumnsToWideTables
      end
    end

    add_concurrent_foreign_key :namespaces, :projects, column: :tmp_project_id

    add_concurrent_index :namespaces, :tmp_project_id, name: INDEX_NAME, unique: true
  end
end