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

20220927171740_prepare_for_vulnerability_occurrences_uuid_type_transition.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e6f3384514d10c418b778accb58bee025ba03335 (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 PrepareForVulnerabilityOccurrencesUuidTypeTransition < Gitlab::Database::Migration[2.0]
  enable_lock_retries!

  TABLE = :vulnerability_occurrences
  MAPPINGS = {
    uuid: {
      from_type: :string,
      to_type: :uuid,
      default_value: '00000000-0000-0000-0000-000000000000'
    }
  }

  def up
    create_temporary_columns_and_triggers(TABLE, MAPPINGS)
  end

  def down
    columns = MAPPINGS.keys
    temporary_columns = columns.map { |column| convert_to_type_column(column, :string, :uuid) }
    trigger_name = rename_trigger_name(TABLE, columns, temporary_columns)
    remove_rename_triggers(TABLE, trigger_name)
    temporary_columns.each { |column| remove_column(TABLE, column) }
  end
end