Commit 7b41ff8a authored by Robert Speicher's avatar Robert Speicher

Merge branch '5646-bad-job-artifact-registry-migration' into 'master'

Resolve "Bad SQL in the migration of job artifact registries to a separate table"

Closes #5646 and #5639

See merge request gitlab-org/gitlab-ee!5345
parents 964086b2 80ef2c5b
---
title: Fix a bug migrating CI job artifact registry entries to a separate table
merge_request: 5345
author:
type: fixed
...@@ -25,7 +25,10 @@ class MigrateCiJobArtifactsToSeparateRegistry < ActiveRecord::Migration ...@@ -25,7 +25,10 @@ class MigrateCiJobArtifactsToSeparateRegistry < ActiveRecord::Migration
$BODY$ $BODY$
BEGIN BEGIN
IF (TG_OP = 'UPDATE') THEN IF (TG_OP = 'UPDATE') THEN
UPDATE job_artifact_registry SET (retry_at, bytes, retry_count, success, sha256) = (NEW.retry_at, NEW.bytes, NEW.retry_count, NEW.success, NEW.sha256); UPDATE job_artifact_registry
SET (retry_at, bytes, retry_count, success, sha256) =
(NEW.retry_at, NEW.bytes, NEW.retry_count, NEW.success, NEW.sha256)
WHERE artifact_id = NEW.file_id;
ELSEIF (TG_OP = 'INSERT') THEN ELSEIF (TG_OP = 'INSERT') THEN
INSERT INTO job_artifact_registry (created_at, retry_at, artifact_id, bytes, retry_count, success, sha256) INSERT INTO job_artifact_registry (created_at, retry_at, artifact_id, bytes, retry_count, success, sha256)
VALUES (NEW.created_at, NEW.retry_at, NEW.file_id, NEW.bytes, NEW.retry_count, NEW.success, NEW.sha256); VALUES (NEW.created_at, NEW.retry_at, NEW.file_id, NEW.bytes, NEW.retry_count, NEW.success, NEW.sha256);
......
...@@ -47,6 +47,8 @@ describe MigrateCiJobArtifactsToSeparateRegistry, :geo, :migration do ...@@ -47,6 +47,8 @@ describe MigrateCiJobArtifactsToSeparateRegistry, :geo, :migration do
entry.update_attributes(success: false, bytes: 10240, sha256: '10' * 64) entry.update_attributes(success: false, bytes: 10240, sha256: '10' * 64)
expect(job_artifact_registry.where(artifact_id: 1, success: false, bytes: 10240, sha256: '10' * 64).count).to eq(1) expect(job_artifact_registry.where(artifact_id: 1, success: false, bytes: 10240, sha256: '10' * 64).count).to eq(1)
# Ensure that *only* the correct job artifact is updated
expect(job_artifact_registry.find_by(artifact_id: 2).bytes).to eq(2048)
end end
it 'creates a new artifact using the next ID' do it 'creates a new artifact using the next ID' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment