summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220121221651_remove_projects_ci_variables_project_id_fk.rb
blob: f647d4376ac1f214b2ce864cfb857d1c04c7a0e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

class RemoveProjectsCiVariablesProjectIdFk < Gitlab::Database::Migration[1.0]
  disable_ddl_transaction!

  def up
    return unless foreign_key_exists?(:ci_variables, :projects, name: "fk_ada5eb64b3")

    with_lock_retries do
      execute('LOCK projects, ci_variables IN ACCESS EXCLUSIVE MODE') if transaction_open?

      remove_foreign_key_if_exists(:ci_variables, :projects, name: "fk_ada5eb64b3")
    end
  end

  def down
    add_concurrent_foreign_key(:ci_variables, :projects, name: "fk_ada5eb64b3", column: :project_id, target_column: :id, on_delete: :cascade)
  end
end