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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
b7d67232
Commit
b7d67232
authored
Jun 28, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add initial build stage_id ref background migration
parent
16ae7b7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
7 deletions
+26
-7
db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
...0170628080858_migrate_stage_id_reference_in_background.rb
+10
-0
lib/gitlab/background_migration/migrate_build_stage_id_reference.rb
.../background_migration/migrate_build_stage_id_reference.rb
+11
-7
spec/migrations/migrate_stage_id_reference_in_background_spec.rb
...grations/migrate_stage_id_reference_in_background_spec.rb
+5
-0
No files found.
db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
View file @
b7d67232
...
...
@@ -3,7 +3,17 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
DOWNTIME
=
false
disable_ddl_transaction!
class
Build
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_builds'
end
def
up
Build
.
find_each
do
|
build
|
BackgroundMigrationWorker
.
perform_async
(
'MigrateBuildStageIdReference'
,
[
build
.
id
])
end
end
def
down
...
...
lib/gitlab/background_migration/migrate_build_stage_id_reference.rb
View file @
b7d67232
module
Gitlab
module
BackgroundMigration
class
MigrateBuildStageIdReference
class
Build
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_builds'
end
def
perform
(
id
)
raise
ArgumentError
unless
id
.
is_a?
(
Integer
)
class
Stage
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_stages'
end
sql
=
<<-
SQL
.
strip_heredoc
UPDATE "ci_builds" SET "stage_id" = (
SELECT id FROM ci_stages
WHERE ci_stages.pipeline_id = ci_builds.commit_id
AND ci_stages.name = ci_builds.stage
)
WHERE "ci_builds"."id" =
#{
id
}
AND "ci_builds"."stage_id" IS NULL
SQL
def
perform
(
id
)
ActiveRecord
::
Base
.
connection
.
execute
(
sql
)
end
end
end
...
...
spec/migrations/migrate_stage_id_reference_in_background_spec.rb
View file @
b7d67232
...
...
@@ -22,5 +22,10 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do
end
it
'schedules background migrations'
do
expect
(
jobs
.
where
(
stage_id:
nil
)).
to
be_present
migrate!
expect
(
jobs
.
where
(
stage_id:
nil
)).
to
be_empty
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