summaryrefslogtreecommitdiff
path: root/db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb
blob: ec6f6df27bcb381d05b38cc15d064885791821b9 (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
# frozen_string_literal: true

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

  BACKGROUND_MIGRATION_CLASS = 'SetNullPackageFilesFileStoreToLocalValue'
  BATCH_SIZE = 5_000
  LOCAL_STORE = 1 # equal to ObjectStorage::Store::LOCAL
  DOWNTIME = false

  disable_ddl_transaction!

  module Packages
    class PackageFile < ActiveRecord::Base
      self.table_name = 'packages_package_files'

      include ::EachBatch
    end
  end

  def up
    Gitlab::BackgroundMigration.steal(BACKGROUND_MIGRATION_CLASS)

    # Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low.
    Packages::PackageFile.where(file_store: nil).each_batch(of: BATCH_SIZE) do |batch, index|
      batch.update_all(file_store: LOCAL_STORE)
    end
  end

  def down
    # no-op
  end
end