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
b5c69ce3
Commit
b5c69ce3
authored
Feb 05, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Retry migration removing stages in case of duplicates
parent
5f57c7a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
4 deletions
+26
-4
db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
...igrate/20180119121225_remove_redundant_pipeline_stages.rb
+17
-4
spec/migrations/remove_redundant_pipeline_stages_spec.rb
spec/migrations/remove_redundant_pipeline_stages_spec.rb
+9
-0
No files found.
db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
View file @
b5c69ce3
...
@@ -3,12 +3,15 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
...
@@ -3,12 +3,15 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
DOWNTIME
=
false
DOWNTIME
=
false
def
up
disable_ddl_transaction!
remove_concurrent_index
:ci_stages
,
[
:pipeline_id
,
:name
]
def
up
(
attempts:
100
)
remove_outdated_index!
remove_redundant_pipeline_stages!
remove_redundant_pipeline_stages!
add_unique_index!
add_concurrent_index
:ci_stages
,
[
:pipeline_id
,
:name
],
unique:
true
rescue
ActiveRecord
::
RecordNotUnique
retry
if
(
attempts
-=
1
)
>
0
raise
end
end
def
down
def
down
...
@@ -18,6 +21,16 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
...
@@ -18,6 +21,16 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
private
private
def
remove_outdated_index!
return
unless
index_exists?
(
:ci_stages
,
[
:pipeline_id
,
:name
])
remove_concurrent_index
:ci_stages
,
[
:pipeline_id
,
:name
]
end
def
add_unique_index!
add_concurrent_index
:ci_stages
,
[
:pipeline_id
,
:name
],
unique:
true
end
def
remove_redundant_pipeline_stages!
def
remove_redundant_pipeline_stages!
redundant_stages_ids
=
<<~
SQL
redundant_stages_ids
=
<<~
SQL
SELECT id FROM ci_stages WHERE (pipeline_id, name) IN (
SELECT id FROM ci_stages WHERE (pipeline_id, name) IN (
...
...
spec/migrations/remove_redundant_pipeline_stages_spec.rb
View file @
b5c69ce3
...
@@ -36,4 +36,13 @@ describe RemoveRedundantPipelineStages, :migration do
...
@@ -36,4 +36,13 @@ describe RemoveRedundantPipelineStages, :migration do
expect
(
builds
.
all
.
count
).
to
eq
6
expect
(
builds
.
all
.
count
).
to
eq
6
expect
(
builds
.
all
.
pluck
(
:stage_id
).
compact
).
to
eq
[
102
]
expect
(
builds
.
all
.
pluck
(
:stage_id
).
compact
).
to
eq
[
102
]
end
end
it
'retries when duplicated stages are being created during migration'
do
allow
(
subject
).
to
receive
(
:remove_outdated_index!
)
expect
(
subject
).
to
receive
(
:remove_redundant_pipeline_stages!
).
exactly
(
3
).
times
allow
(
subject
).
to
receive
(
:add_unique_index!
)
.
and_raise
(
ActiveRecord
::
RecordNotUnique
.
new
(
'Duplicated stages present!'
))
expect
{
subject
.
up
(
attempts:
3
)
}.
to
raise_error
ActiveRecord
::
RecordNotUnique
end
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