summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210513155546_backfill_nuget_temporary_packages_to_processing_status.rb
blob: 8124f94b519d5aba288667c62ac44065619d0b88 (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
# frozen_string_literal: true

class BackfillNugetTemporaryPackagesToProcessingStatus < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  disable_ddl_transaction!

  class Package < ActiveRecord::Base
    include EachBatch

    self.table_name = 'packages_packages'

    scope :nuget_temporary_packages, -> do
      # 4 is nuget package type, 0 is default status
      where(package_type: 4, name: 'NuGet.Temporary.Package', status: 0)
    end
  end

  def up
    Package.nuget_temporary_packages.each_batch(of: 100) do |batch|
      # 2 is processing status
      batch.update_all(status: 2)
    end
  end

  def down
    # no-op
  end
end