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
49da5a20
Commit
49da5a20
authored
Jun 21, 2017
by
Kamil Trzciński
Committed by
kushalpandya
Jun 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'fix/gb/improve-build-stage-reference-migration' into 'master'
Improve build stages reference migration Closes #33866 See merge request !12337
parent
88567c35
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
77 additions
and
25 deletions
+77
-25
20170526185602_add_stage_id_to_ci_builds.rb
db/migrate/20170526185602_add_stage_id_to_ci_builds.rb
+0
-8
20170526185901_remove_stage_id_index_from_builds.rb
...grate/20170526185901_remove_stage_id_index_from_builds.rb
+18
-0
20170526185921_migrate_build_stage_reference.rb
...t_migrate/20170526185921_migrate_build_stage_reference.rb
+8
-14
20170526190000_migrate_build_stage_reference_again.rb
...ate/20170526190000_migrate_build_stage_reference_again.rb
+27
-0
20170621102400_add_stage_id_index_to_builds.rb
...st_migrate/20170621102400_add_stage_id_index_to_builds.rb
+21
-0
schema.rb
db/schema.rb
+1
-1
migrate_build_stage_reference_again_spec.rb
spec/migrations/migrate_build_stage_reference_again_spec.rb
+2
-2
No files found.
db/migrate/20170526185602_add_stage_id_to_ci_builds.rb
View file @
49da5a20
...
@@ -3,19 +3,11 @@ class AddStageIdToCiBuilds < ActiveRecord::Migration
...
@@ -3,19 +3,11 @@ class AddStageIdToCiBuilds < ActiveRecord::Migration
DOWNTIME
=
false
DOWNTIME
=
false
disable_ddl_transaction!
def
up
def
up
add_column
:ci_builds
,
:stage_id
,
:integer
add_column
:ci_builds
,
:stage_id
,
:integer
add_concurrent_foreign_key
:ci_builds
,
:ci_stages
,
column: :stage_id
,
on_delete: :cascade
add_concurrent_index
:ci_builds
,
:stage_id
end
end
def
down
def
down
remove_foreign_key
:ci_builds
,
column: :stage_id
remove_concurrent_index
:ci_builds
,
:stage_id
remove_column
:ci_builds
,
:stage_id
,
:integer
remove_column
:ci_builds
,
:stage_id
,
:integer
end
end
end
end
db/post_migrate/20170526185901_remove_stage_id_index_from_builds.rb
0 → 100644
View file @
49da5a20
class
RemoveStageIdIndexFromBuilds
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
if
index_exists?
(
:ci_builds
,
:stage_id
)
remove_foreign_key
(
:ci_builds
,
column: :stage_id
)
remove_concurrent_index
(
:ci_builds
,
:stage_id
)
end
end
def
down
# noop
end
end
db/post_migrate/20170526185921_migrate_build_stage_reference.rb
View file @
49da5a20
...
@@ -3,23 +3,17 @@ class MigrateBuildStageReference < ActiveRecord::Migration
...
@@ -3,23 +3,17 @@ class MigrateBuildStageReference < ActiveRecord::Migration
DOWNTIME
=
false
DOWNTIME
=
false
def
up
##
disable_statement_timeout
# This is an empty migration, content has been moved to a new one:
# post migrate 20170526190000 MigrateBuildStageReferenceAgain
stage_id
=
Arel
.
sql
<<-
SQL
.
strip_heredoc
#
(SELECT id FROM ci_stages
# See gitlab-org/gitlab-ce!12337 for more details.
WHERE ci_stages.pipeline_id = ci_builds.commit_id
AND ci_stages.name = ci_builds.stage)
SQL
update_column_in_batches
(
:ci_builds
,
:stage_id
,
stage_id
)
do
|
table
,
query
|
def
up
query
.
where
(
table
[
:stage_id
].
eq
(
nil
))
# noop
end
end
end
def
down
def
down
disable_statement_timeout
# noop
update_column_in_batches
(
:ci_builds
,
:stage_id
,
nil
)
end
end
end
end
db/post_migrate/20170526190000_migrate_build_stage_reference_again.rb
0 → 100644
View file @
49da5a20
class
MigrateBuildStageReferenceAgain
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
disable_statement_timeout
stage_id
=
Arel
.
sql
<<-
SQL
.
strip_heredoc
(SELECT id FROM ci_stages
WHERE ci_stages.pipeline_id = ci_builds.commit_id
AND ci_stages.name = ci_builds.stage)
SQL
update_column_in_batches
(
:ci_builds
,
:stage_id
,
stage_id
)
do
|
table
,
query
|
query
.
where
(
table
[
:stage_id
].
eq
(
nil
))
end
end
def
down
disable_statement_timeout
update_column_in_batches
(
:ci_builds
,
:stage_id
,
nil
)
end
end
db/post_migrate/20170621102400_add_stage_id_index_to_builds.rb
0 → 100644
View file @
49da5a20
class
AddStageIdIndexToBuilds
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
unless
index_exists?
(
:ci_builds
,
:stage_id
)
add_concurrent_foreign_key
(
:ci_builds
,
:ci_stages
,
column: :stage_id
,
on_delete: :cascade
)
add_concurrent_index
(
:ci_builds
,
:stage_id
)
end
end
def
down
if
index_exists?
(
:ci_builds
,
:stage_id
)
remove_foreign_key
(
:ci_builds
,
column: :stage_id
)
remove_concurrent_index
(
:ci_builds
,
:stage_id
)
end
end
end
db/schema.rb
View file @
49da5a20
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201706
19144837
)
do
ActiveRecord
::
Schema
.
define
(
version:
201706
21102400
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
...
spec/migrations/migrate_build_stage_reference_spec.rb
→
spec/migrations/migrate_build_stage_reference_
again_
spec.rb
View file @
49da5a20
require
'spec_helper'
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'201705261
85921_migrate_build_stage_reference
.rb'
)
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'201705261
90000_migrate_build_stage_reference_again
.rb'
)
describe
MigrateBuildStageReference
,
:migration
do
describe
MigrateBuildStageReference
Again
,
:migration
do
##
##
# Create test data - pipeline and CI/CD jobs.
# Create test data - pipeline and CI/CD jobs.
#
#
...
...
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