Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
57ab71a0
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,发现更多精彩内容 >>
提交
57ab71a0
编写于
5月 28, 2018
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize queries. Add some tests for filtering logic.
上级
8f24dfaa
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
18 deletion
+30
-18
db/post_migrate/20180427161409_migrate_legacy_artifacts_to_job_artifacts.rb
...180427161409_migrate_legacy_artifacts_to_job_artifacts.rb
+12
-8
lib/gitlab/background_migration/migrate_legacy_artifacts.rb
lib/gitlab/background_migration/migrate_legacy_artifacts.rb
+2
-4
spec/migrations/migrate_legacy_artifacts_to_job_artifacts_spec.rb
...rations/migrate_legacy_artifacts_to_job_artifacts_spec.rb
+16
-6
未找到文件。
db/post_migrate/20180427161409_migrate_legacy_artifacts_to_job_artifacts.rb
浏览文件 @
57ab71a0
...
...
@@ -12,19 +12,23 @@ class MigrateLegacyArtifactsToJobArtifacts < ActiveRecord::Migration
self
.
table_name
=
'ci_builds'
self
.
inheritance_column
=
:_type_disabled
# disable STI
##
# Jobs which have a value on `artifacts_file` column are targetted.
# In addition, jobs which have already had job_artifacts are untargetted.
# This usually doesn't happen, however, if it's the case, background migrations will be aborted
scope
:legacy_artifacts
,
->
do
where
(
'artifacts_file IS NOT NULL AND artifacts_file <> ?'
,
''
)
end
scope
:legacy_artifacts
,
->
{
where
(
"artifacts_file <> ''"
)
}
scope
:without_new_artifacts
,
->
do
where
(
'NOT EXISTS (
SELECT 1 FROM ci_job_artifacts WHERE ci_job_artifacts.id = ci_builds.id AND (file_type = 1 OR file_type = 2))'
)
where
(
'NOT EXISTS (
?)'
,
MigrateLegacyArtifactsToJobArtifacts
::
JobArtifact
.
select
(
1
).
where
(
'ci_builds.id = ci_job_artifacts.job_id'
).
archive
)
end
end
class
JobArtifact
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_job_artifacts'
enum
file_type:
{
archive:
1
,
metadata:
2
,
trace:
3
}
end
def
up
disable_statement_timeout
...
...
lib/gitlab/background_migration/migrate_legacy_artifacts.rb
浏览文件 @
57ab71a0
...
...
@@ -9,12 +9,10 @@ module Gitlab
self
.
table_name
=
'ci_builds'
self
.
inheritance_column
=
:_type_disabled
scope
:legacy_artifacts
,
->
do
where
(
'artifacts_file IS NOT NULL AND artifacts_file <> ?'
,
''
)
end
scope
:legacy_artifacts
,
->
{
where
(
"artifacts_file <> ''"
)
}
scope
:without_new_artifacts
,
->
do
where
(
'NOT EXISTS (
SELECT 1 FROM ci_job_artifacts WHERE ci_job_artifacts.id = ci_builds.id AND (file_type = 1 OR file_type = 2))'
)
where
(
'NOT EXISTS (
?)'
,
MigrateLegacyArtifacts
::
JobArtifact
.
select
(
1
).
where
(
'ci_builds.id = ci_job_artifacts.job_id'
).
archive
)
end
end
...
...
spec/migrations/migrate_legacy_artifacts_to_job_artifacts_spec.rb
浏览文件 @
57ab71a0
...
...
@@ -17,9 +17,13 @@ describe MigrateLegacyArtifactsToJobArtifacts, :migration, :sidekiq do
pipelines
.
create!
(
id:
1
,
project_id:
1
,
ref:
'master'
,
sha:
'adf43c3a'
)
end
context
'when
a legacy artifacts exists
'
do
context
'when
legacy artifacts exist
'
do
before
do
jobs
.
create!
(
id:
1
,
commit_id:
1
,
project_id:
1
,
status: :success
,
artifacts_file:
'archive.zip'
,
artifacts_metadata:
'metadata.gz'
)
jobs
.
create!
(
id:
2
,
commit_id:
1
,
project_id:
1
,
status: :failed
,
artifacts_file:
'archive.zip'
,
artifacts_metadata:
'metadata.gz'
)
jobs
.
create!
(
id:
3
,
commit_id:
1
,
project_id:
1
,
status: :running
)
jobs
.
create!
(
id:
4
,
commit_id:
1
,
project_id:
1
,
status: :success
,
artifacts_file:
'archive.zip'
,
artifacts_metadata:
'metadata.gz'
)
jobs
.
create!
(
id:
5
,
commit_id:
1
,
project_id:
1
,
status: :failed
,
artifacts_file:
'archive.zip'
,
artifacts_metadata:
'metadata.gz'
)
end
it
'schedules a background migration'
do
...
...
@@ -27,7 +31,7 @@ describe MigrateLegacyArtifactsToJobArtifacts, :migration, :sidekiq do
Timecop
.
freeze
do
migrate!
expect
(
migration_name
).
to
be_scheduled_delayed_migration
(
5
.
minutes
,
1
,
1
)
expect
(
migration_name
).
to
be_scheduled_delayed_migration
(
5
.
minutes
,
1
,
5
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
1
end
end
...
...
@@ -36,13 +40,17 @@ describe MigrateLegacyArtifactsToJobArtifacts, :migration, :sidekiq do
context
'when new artifacts has already existed'
do
before
do
job_artifacts
.
create!
(
id:
1
,
project_id:
1
,
job_id:
1
,
file_type:
1
,
size:
123
,
file:
'archive.zip'
)
job_artifacts
.
create!
(
id:
2
,
project_id:
1
,
job_id:
5
,
file_type:
1
,
size:
123
,
file:
'archive.zip'
)
end
it
'does not schedule background migrations'
do
Sidekiq
::
Testing
.
fake!
do
migrate!
Timecop
.
freeze
do
migrate!
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
0
expect
(
migration_name
).
to
be_scheduled_delayed_migration
(
5
.
minutes
,
2
,
4
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
1
end
end
end
end
...
...
@@ -55,9 +63,11 @@ describe MigrateLegacyArtifactsToJobArtifacts, :migration, :sidekiq do
it
'does not schedule background migrations'
do
Sidekiq
::
Testing
.
fake!
do
migrate!
Timecop
.
freeze
do
migrate!
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
0
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
0
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录