Skip to content
Snippets Groups Projects
Commit a2eb053d authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Wrap insertion and deletion in a single transaction

parent d4bb2c70
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -38,36 +38,38 @@ module Gitlab
end
 
def perform(start_id, stop_id)
rows = []
ActiveRecord::Base.transaction do
rows = []
 
# Build rows
MigrateLegacyArtifacts::Build
.legacy_artifacts.without_new_artifacts
.where(id: (start_id..stop_id)).find_each do |build|
rows << build_archive_row(build)
rows << build_metadata_row(build) if build.artifacts_metadata
end
# Build rows
MigrateLegacyArtifacts::Build
.legacy_artifacts.without_new_artifacts
.where(id: (start_id..stop_id)).find_each do |build|
rows << build_archive_row(build)
rows << build_metadata_row(build) if build.artifacts_metadata
end
 
# Bulk insert
Gitlab::Database
.bulk_insert(MigrateLegacyArtifacts::JobArtifact.table_name, rows)
# Bulk insert
Gitlab::Database
.bulk_insert(MigrateLegacyArtifacts::JobArtifact.table_name, rows)
 
# Clean columns of ci_builds
#
# Included
# "artifacts_file", "artifacts_metadata", "artifacts_size", "artifacts_file_store", "artifacts_metadata_store"
# Excluded
# - "artifacts_expire_at"
# This is still used to process the expiration logic of job artifacts.
# We also store the same value to `ci_job_artifacts.expire_at`, however it's not used at the moment.
MigrateLegacyArtifacts::Build
.legacy_artifacts
.where(id: (start_id..stop_id))
.update_all(artifacts_file: nil,
artifacts_file_store: nil,
artifacts_size: nil,
artifacts_metadata: nil,
artifacts_metadata_store: nil)
# Clean columns of ci_builds
#
# Included
# "artifacts_file", "artifacts_metadata", "artifacts_size", "artifacts_file_store", "artifacts_metadata_store"
# Excluded
# - "artifacts_expire_at"
# This is still used to process the expiration logic of job artifacts.
# We also store the same value to `ci_job_artifacts.expire_at`, however it's not used at the moment.
MigrateLegacyArtifacts::Build
.legacy_artifacts
.where(id: (start_id..stop_id))
.update_all(artifacts_file: nil,
artifacts_file_store: nil,
artifacts_size: nil,
artifacts_metadata: nil,
artifacts_metadata_store: nil)
end
end
 
private
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment