提交 a2eb053d 编写于 作者: S Shinya Maeda

Wrap insertion and deletion in a single transaction

上级 d4bb2c70
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册