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

20220425121435_backfill_integrations_enable_ssl_verification.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 101bde975dbcfff4ab55fe22a8b97bbd8fdd7f9d (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
54
55
56
57
# frozen_string_literal: true

class BackfillIntegrationsEnableSslVerification < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!
  restrict_gitlab_migration gitlab_schema: :gitlab_main

  MIGRATION = 'BackfillIntegrationsEnableSslVerification'
  INTERVAL = 5.minutes
  BATCH_SIZE = 1_000

  class Integration < MigrationRecord
    include EachBatch
    include IgnorableColumns

    self.table_name = :integrations
    self.inheritance_column = :_type_disabled

    ignore_column :template, remove_with: '15.0', remove_after: '2022-04-22'
    ignore_column :type, remove_with: '15.0', remove_after: '2022-04-22'
    ignore_column :properties, remove_with: '15.1', remove_after: '2022-05-22'

    scope :affected, -> do
      where(type_new: %w[Integrations::DroneCi Integrations::Teamcity]).where.not(encrypted_properties: nil)
    end

    attr_encrypted :properties,
                  mode: :per_attribute_iv,
                  key: Settings.attr_encrypted_db_key_base_32,
                  algorithm: 'aes-256-gcm',
                  marshal: true,
                  marshaler: ::Gitlab::Json,
                  encode: false,
                  encode_iv: false

    # Handle assignment of props with symbol keys.
    # To do this correctly, we need to call the method generated by attr_encrypted.
    alias_method :attr_encrypted_props=, :properties=
    private :attr_encrypted_props=

    def properties=(props)
      self.attr_encrypted_props = props&.with_indifferent_access&.freeze
    end
  end

  def up
    queue_background_migration_jobs_by_range_at_intervals(
      Integration.affected,
      MIGRATION,
      INTERVAL,
      batch_size: BATCH_SIZE,
      track_jobs: true
    )
  end

  def down
  end
end