summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220112090556_remove_cascade_delete_from_project_namespace_foreign_key.rb
blob: d786c9d846a37a76d686a4e93f8f45ebea50b365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

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

  TARGET_COLUMN = :project_namespace_id

  def up
    with_lock_retries do
      remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN)
    end

    add_concurrent_foreign_key(:projects, :namespaces, column: TARGET_COLUMN, on_delete: :nullify)
  end

  def down
    with_lock_retries do
      remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN)
    end

    add_concurrent_foreign_key(:projects, :namespaces, column: TARGET_COLUMN, on_delete: :cascade)
  end
end