BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
7f31768a
Commit
7f31768a
authored
May 22, 2017
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix-retried-for-mysql' into 'master'
Fixes broken MySQL migration for retried Closes #32647 See merge request !11593
parents
b94398e9
cbafe24a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
3 deletions
+43
-3
20170503004427_upate_retried_for_ci_build.rb
db/post_migrate/20170503004427_upate_retried_for_ci_build.rb
+26
-3
upate_retried_for_ci_builds_spec.rb
spec/migrations/upate_retried_for_ci_builds_spec.rb
+17
-0
No files found.
db/post_migrate/20170503004427_upate_retried_for_ci_build.rb
View file @
7f31768a
...
...
@@ -8,6 +8,32 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration
def
up
disable_statement_timeout
if
Gitlab
::
Database
.
mysql?
up_mysql
else
up_postgres
end
end
def
down
end
private
def
up_mysql
# This is a trick to overcome MySQL limitation:
# Mysql2::Error: Table 'ci_builds' is specified twice, both as a target for 'UPDATE' and as a separate source for data
# However, this leads to create a temporary table from `max(ci_builds.id)` which is slow and do full database update
execute
<<-
SQL
.
strip_heredoc
UPDATE ci_builds SET retried=
(id NOT IN (
SELECT * FROM (SELECT MAX(ci_builds.id) FROM ci_builds GROUP BY commit_id, name) AS latest_jobs
))
WHERE retried IS NULL
SQL
end
def
up_postgres
with_temporary_partial_index
do
latest_id
=
<<-
SQL
.
strip_heredoc
SELECT MAX(ci_builds2.id)
...
...
@@ -26,9 +52,6 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration
end
end
def
down
end
def
with_temporary_partial_index
if
Gitlab
::
Database
.
postgresql?
execute
'CREATE INDEX CONCURRENTLY IF NOT EXISTS index_for_ci_builds_retried_migration ON ci_builds (id) WHERE retried IS NULL;'
...
...
spec/migrations/upate_retried_for_ci_builds_spec.rb
0 → 100644
View file @
7f31768a
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170503004427_upate_retried_for_ci_build.rb'
)
describe
UpateRetriedForCiBuild
,
truncate:
true
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let!
(
:build_old
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
'test'
)
}
let!
(
:build_new
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
'test'
)
}
before
do
described_class
.
new
.
up
end
it
'updates ci_builds.is_retried'
do
expect
(
build_old
.
reload
).
to
be_retried
expect
(
build_new
.
reload
).
not_to
be_retried
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