summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210819145000_drop_temporary_columns_and_triggers_for_ci_builds_runner_session.rb
blob: bbcee55602064e136afd337e7a0455c2b14a7185 (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
28
# frozen_string_literal: true

class DropTemporaryColumnsAndTriggersForCiBuildsRunnerSession < ActiveRecord::Migration[6.1]
  include Gitlab::Database::MigrationHelpers

  disable_ddl_transaction!

  TABLE = 'ci_builds_runner_session'
  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