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

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

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

  DOWNTIME = false
  CONSTRAINT_NAME = 'fk_timelogs_note_id'

  disable_ddl_transaction!

  def up
    add_concurrent_foreign_key :timelogs, :notes, column: :note_id, on_delete: :nullify, name: CONSTRAINT_NAME

    with_lock_retries do
      remove_foreign_key_if_exists :timelogs, :notes, column: :note_id, on_delete: :cascade
    end
  end

  def down
    add_concurrent_foreign_key :timelogs, :notes, column: :note_id, on_delete: :cascade

    with_lock_retries do
      remove_foreign_key_if_exists :timelogs, :notes, column: :note_id, on_delete: :nullify, name: CONSTRAINT_NAME
    end
  end
end