diff options
Diffstat (limited to 'db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb')
-rw-r--r-- | db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb b/db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb new file mode 100644 index 00000000000..ec6f6df27bc --- /dev/null +++ b/db/post_migrate/20200915185707_ensure_filled_file_store_on_package_files.rb @@ -0,0 +1,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 |