debian-mirror-gitlab/lib/gitlab/terraform/state_migration_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
769 B
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
module Gitlab
module Terraform
class StateMigrationHelper
class << self
def migrate_to_remote_storage(&block)
migrate_in_batches(
::Terraform::StateVersion.with_files_stored_locally.preload_state,
::Terraform::StateUploader::Store::REMOTE,
&block
)
end
private
def batch_size
ENV.fetch('MIGRATION_BATCH_SIZE', 10).to_i
end
def migrate_in_batches(versions, store, &block)
versions.find_each(batch_size: batch_size) do |version| # rubocop:disable CodeReuse/ActiveRecord
version.file.migrate!(store)
2022-08-27 11:52:29 +05:30
yield version if block
2021-03-11 19:13:27 +05:30
end
end
end
end
end
end