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

20210610102413_migrate_protected_attribute_to_pending_builds.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 47a6e39e87af3e7e0067bc5094a7fe83c093f822 (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 MigrateProtectedAttributeToPendingBuilds < ActiveRecord::Migration[6.1]
  include ::Gitlab::Database::DynamicModelHelpers

  disable_ddl_transaction!

  def up
    return unless Gitlab.dev_or_test_env? || Gitlab.com?

    each_batch_range('ci_pending_builds', connection: connection, of: 1000) do |min, max|
      execute <<~SQL
        UPDATE ci_pending_builds
          SET protected = true
        FROM ci_builds
          WHERE ci_pending_builds.build_id = ci_builds.id
            AND ci_builds.protected = true
            AND ci_pending_builds.id BETWEEN #{min} AND #{max}
      SQL
    end
  end

  def down
    # no op
  end
end