summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210902144144_drop_temporary_columns_and_triggers_for_ci_build_needs.rb
blob: f04c5cd65613ae364952d984dc21e62743538213 (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 DropTemporaryColumnsAndTriggersForCiBuildNeeds < Gitlab::Database::Migration[1.0]
  disable_ddl_transaction!

  TABLE = 'ci_build_needs'
  TEMPORARY_COLUMN = 'build_id_convert_to_bigint'
  MAIN_COLUMN = 'build_id'

  # rubocop:disable Migration/WithLockRetriesDisallowedMethod
  def up
    with_lock_retries do
      cleanup_conversion_of_integer_to_bigint(TABLE, MAIN_COLUMN)
    end
  end

  def down
    check_trigger_permissions!(TABLE)

    with_lock_retries do
      add_column(TABLE, TEMPORARY_COLUMN, :int, default: 0, null: false)
      install_rename_triggers(TABLE, MAIN_COLUMN, TEMPORARY_COLUMN)
    end
  end
  # rubocop:enable Migration/WithLockRetriesDisallowedMethod
end