Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
696c030d
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
696c030d
编写于
6月 06, 2018
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix static analysys. Split methods. Use `file_types`
上级
86217c65
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
80 addition
and
62 deletion
+80
-62
lib/gitlab/background_migration/migrate_legacy_artifacts.rb
lib/gitlab/background_migration/migrate_legacy_artifacts.rb
+80
-62
未找到文件。
lib/gitlab/background_migration/migrate_legacy_artifacts.rb
浏览文件 @
696c030d
...
...
@@ -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%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录