Commit 696c030d authored by Shinya Maeda's avatar Shinya Maeda

Fix static analysys. Split methods. Use `file_types`

parent 86217c65
......@@ -41,70 +41,88 @@ module Gitlab
def perform(start_id, stop_id)
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute <<-EOF.strip_heredoc
INSERT INTO ci_job_artifacts (
project_id,
job_id,
expire_at,
file_location,
created_at,
updated_at,
file,
size,
file_store,
file_type)
SELECT project_id,
id,
artifacts_expire_at,
#{MigrateLegacyArtifacts::JobArtifact.file_locations['legacy_path']},
created_at,
created_at,
artifacts_file,
artifacts_size,
COALESCE(artifacts_file_store, #{JobArtifact::LOCAL_STORE}),
#{MigrateLegacyArtifacts::JobArtifact.file_types['archive']}
FROM ci_builds
WHERE id BETWEEN #{start_id.to_i} AND #{stop_id.to_i}
AND artifacts_file <> '' AND artifacts_metadata <> ''
AND NOT EXISTS (SELECT 1 FROM ci_job_artifacts WHERE (ci_builds.id = ci_job_artifacts.job_id) AND ci_job_artifacts.file_type = 1)
EOF
insert_archives(start_id, stop_id)
insert_metadatas(start_id, stop_id)
delete_legacy_artifacts(start_id, stop_id)
end
end
ActiveRecord::Base.connection.execute <<-EOF.strip_heredoc
INSERT INTO ci_job_artifacts (
project_id,
job_id,
expire_at,
file_location,
created_at,
updated_at,
file,
size,
file_store,
file_type)
SELECT project_id,
id,
artifacts_expire_at,
#{MigrateLegacyArtifacts::JobArtifact.file_locations['legacy_path']},
created_at,
created_at,
artifacts_metadata,
NULL,
COALESCE(artifacts_metadata_store, #{JobArtifact::LOCAL_STORE}),
#{MigrateLegacyArtifacts::JobArtifact.file_types['metadata']}
FROM ci_builds
WHERE id BETWEEN #{start_id.to_i} AND #{stop_id.to_i}
AND artifacts_file <> '' AND artifacts_metadata <> ''
AND NOT EXISTS (SELECT 1 FROM ci_job_artifacts WHERE (ci_builds.id = ci_job_artifacts.job_id) AND ci_job_artifacts.file_type = 2)
EOF
private
ActiveRecord::Base.connection.execute <<-EOF.strip_heredoc
UPDATE ci_builds SET
artifacts_file = NULL, artifacts_size = NULL, artifacts_file_store = NULL,
artifacts_metadata = NULL, artifacts_metadata_store = NULL
WHERE id BETWEEN #{start_id.to_i} AND #{stop_id.to_i}
AND (artifacts_file <> '' OR artifacts_metadata <> '')
EOF
end
def insert_archives(start_id, stop_id)
ActiveRecord::Base.connection.execute <<-EOF.strip_heredoc
INSERT INTO ci_job_artifacts (
project_id,
job_id,
expire_at,
file_location,
created_at,
updated_at,
file,
size,
file_store,
file_type)
SELECT project_id,
id,
artifacts_expire_at,
#{MigrateLegacyArtifacts::JobArtifact.file_locations['legacy_path']},
created_at,
created_at,
artifacts_file,
artifacts_size,
COALESCE(artifacts_file_store, #{JobArtifact::LOCAL_STORE}),
#{MigrateLegacyArtifacts::JobArtifact.file_types['archive']}
FROM ci_builds
WHERE id BETWEEN #{start_id.to_i} AND #{stop_id.to_i}
AND artifacts_file <> ''
AND NOT EXISTS (
SELECT 1 FROM ci_job_artifacts
WHERE (ci_builds.id = ci_job_artifacts.job_id)
AND ci_job_artifacts.file_type = #{MigrateLegacyArtifacts::JobArtifact.file_types['archive']})
EOF
end
def insert_metadatas(start_id, stop_id)
ActiveRecord::Base.connection.execute <<-EOF.strip_heredoc
INSERT INTO ci_job_artifacts (
project_id,
job_id,
expire_at,
file_location,
created_at,
updated_at,
file,
size,
file_store,
file_type)
SELECT project_id,
id,
artifacts_expire_at,
#{MigrateLegacyArtifacts::JobArtifact.file_locations['legacy_path']},
created_at,
created_at,
artifacts_metadata,
NULL,
COALESCE(artifacts_metadata_store, #{JobArtifact::LOCAL_STORE}),
#{MigrateLegacyArtifacts::JobArtifact.file_types['metadata']}
FROM ci_builds
WHERE id BETWEEN #{start_id.to_i} AND #{stop_id.to_i}
AND artifacts_file <> '' AND artifacts_metadata <> ''
AND NOT EXISTS (
SELECT 1 FROM ci_job_artifacts
WHERE (ci_builds.id = ci_job_artifacts.job_id)
AND ci_job_artifacts.file_type = #{MigrateLegacyArtifacts::JobArtifact.file_types['metadata']})
EOF
end
def delete_legacy_artifacts(start_id, stop_id)
ActiveRecord::Base.connection.execute <<-EOF.strip_heredoc
UPDATE ci_builds SET
artifacts_file = NULL, artifacts_size = NULL, artifacts_file_store = NULL,
artifacts_metadata = NULL, artifacts_metadata_store = NULL
WHERE id BETWEEN #{start_id.to_i} AND #{stop_id.to_i}
AND (artifacts_file <> '' OR artifacts_metadata <> '')
EOF
end
end
end
......
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