Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
02999234
Commit
02999234
authored
Apr 20, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add background migration that migrates stages indices
parent
3b04a3dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
lib/gitlab/background_migration/migrate_stage_index.rb
lib/gitlab/background_migration/migrate_stage_index.rb
+27
-0
spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb
...b/gitlab/background_migration/migrate_stage_index_spec.rb
+36
-0
No files found.
lib/gitlab/background_migration/migrate_stage_index.rb
0 → 100644
View file @
02999234
# frozen_string_literal: true
# rubocop:disable Style/Documentation
module
Gitlab
module
BackgroundMigration
class
MigrateStageIndex
module
Migratable
class
Stage
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_stages'
end
end
def
perform
(
start_id
,
stop_id
)
sql
=
<<~
SQL
UPDATE ci_stages
SET index =
(SELECT stage_idx FROM ci_builds
WHERE ci_builds.stage_id = ci_stages.id
GROUP BY ci_builds.stage_idx ORDER BY COUNT(*) DESC LIMIT 1)
WHERE ci_stages.id BETWEEN
#{
start_id
.
to_i
}
AND
#{
stop_id
.
to_i
}
SQL
ActiveRecord
::
Base
.
connection
.
execute
(
sql
)
end
end
end
end
spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb
0 → 100644
View file @
02999234
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
MigrateStageIndex
,
:migration
,
schema:
20180420080616
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:pipelines
)
{
table
(
:ci_pipelines
)
}
let
(
:stages
)
{
table
(
:ci_stages
)
}
let
(
:jobs
)
{
table
(
:ci_builds
)
}
before
do
namespaces
.
create
(
id:
10
,
name:
'gitlab-org'
,
path:
'gitlab-org'
)
projects
.
create!
(
id:
11
,
namespace_id:
10
,
name:
'gitlab'
,
path:
'gitlab'
)
pipelines
.
create!
(
id:
12
,
project_id:
11
,
ref:
'master'
,
sha:
'adf43c3a'
)
stages
.
create
(
id:
100
,
project_id:
11
,
pipeline_id:
12
,
name:
'build'
)
stages
.
create
(
id:
101
,
project_id:
11
,
pipeline_id:
12
,
name:
'test'
)
jobs
.
create!
(
id:
121
,
commit_id:
12
,
project_id:
11
,
stage_idx:
2
,
stage_id:
100
)
jobs
.
create!
(
id:
122
,
commit_id:
12
,
project_id:
11
,
stage_idx:
2
,
stage_id:
100
)
jobs
.
create!
(
id:
123
,
commit_id:
12
,
project_id:
11
,
stage_idx:
10
,
stage_id:
100
)
jobs
.
create!
(
id:
124
,
commit_id:
12
,
project_id:
11
,
stage_idx:
3
,
stage_id:
101
)
end
it
'correctly migrates stages indices'
do
expect
(
stages
.
all
.
pluck
(
:index
)).
to
all
(
be_nil
)
described_class
.
new
.
perform
(
100
,
101
)
expect
(
stages
.
all
.
pluck
(
:index
)).
to
eq
[
2
,
3
]
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment