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

20231120070345_cleanup_ci_stages_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: c9238eb7272005de37804c3f56fafa3e6b288d35 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

class CleanupCiStagesPipelineIdBigint < Gitlab::Database::Migration[2.2]
  include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum

  disable_ddl_transaction!
  milestone "16.7"

  TABLE = :ci_stages
  REFERENCING_TABLE = :ci_pipelines
  COLUMN = :pipeline_id
  OLD_COLUMN = :pipeline_id_convert_to_bigint
  INDEXES = {
    'index_ci_stages_on_pipeline_id_convert_to_bigint_and_name' => [
      [:pipeline_id_convert_to_bigint, :name], { unique: true }
    ],
    'index_ci_stages_on_pipeline_id_convert_to_bigint' => [
      [:pipeline_id_convert_to_bigint], {}
    ],
    'index_ci_stages_on_pipeline_id_convert_to_bigint_and_id' => [
      [:pipeline_id_convert_to_bigint, :id], { where: 'status = ANY (ARRAY[0, 1, 2, 8, 9, 10])' }
    ],
    'index_ci_stages_on_pipeline_id_convert_to_bigint_and_position' => [
      [:pipeline_id_convert_to_bigint, :position], {}
    ]
  }
  OLD_FK_NAME = :fk_c5ddde695f

  def up
    return unless can_execute_on?(:ci_pipelines, :ci_stages)

    with_lock_retries(raise_on_exhaustion: true) do
      lock_tables(REFERENCING_TABLE, TABLE)
      cleanup_conversion_of_integer_to_bigint(TABLE, [COLUMN])
    end
  end

  def down
    return unless can_execute_on?(:ci_pipelines, :ci_stages)

    restore_conversion_of_integer_to_bigint(TABLE, [COLUMN])

    INDEXES.each do |index_name, (columns, options)|
      add_concurrent_index(TABLE, columns, name: index_name, **options)
    end

    add_concurrent_foreign_key(
      TABLE, REFERENCING_TABLE,
      column: OLD_COLUMN, name: OLD_FK_NAME,
      on_delete: :cascade, validate: true, reverse_lock_order: true
    )
  end
end