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

20231024080150_cleanup_ci_sources_pipelines_pipeline_id_bigint.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6aa8019a1821249969c90d850e26238685f67e58 (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
29
30
31
32
33
34
35
# frozen_string_literal: true

class CleanupCiSourcesPipelinesPipelineIdBigint < Gitlab::Database::Migration[2.1]
  disable_ddl_transaction!

  TABLE = :ci_sources_pipelines
  REFERENCING_TABLE = :ci_pipelines
  COLUMNS = [:pipeline_id, :source_pipeline_id]

  def up
    with_lock_retries(raise_on_exhaustion: true) do
      lock_tables(:ci_pipelines, TABLE)
      cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS) # rubocop:disable Migration/WithLockRetriesDisallowedMethod
    end
  end

  def down
    restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)

    add_concurrent_index(TABLE, :pipeline_id_convert_to_bigint,
      name: :index_ci_sources_pipelines_on_pipeline_id_bigint)
    add_concurrent_index(TABLE, :source_pipeline_id_convert_to_bigint,
      name: :index_ci_sources_pipelines_on_source_pipeline_id_bigint)
    add_concurrent_foreign_key(
      TABLE, REFERENCING_TABLE,
      column: :pipeline_id_convert_to_bigint,
      on_delete: :cascade, validate: true, reverse_lock_order: true
    )
    add_concurrent_foreign_key(
      TABLE, REFERENCING_TABLE,
      column: :source_pipeline_id_convert_to_bigint,
      on_delete: :cascade, validate: true, reverse_lock_order: true
    )
  end
end