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
6d666b21
Commit
6d666b21
authored
Jun 15, 2021
by
Krasimir Angelov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add rake task to finalize batched background migration inline
https://gitlab.com/gitlab-org/gitlab/-/issues/292874
parent
aef36f40
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
11 deletions
+53
-11
lib/gitlab/database/background_migration/batched_migration_runner.rb
...database/background_migration/batched_migration_runner.rb
+9
-8
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+5
-1
lib/tasks/gitlab/background_migrations.rake
lib/tasks/gitlab/background_migrations.rake
+23
-0
spec/lib/gitlab/database/background_migration/batched_migration_runner_spec.rb
...ase/background_migration/batched_migration_runner_spec.rb
+10
-0
spec/lib/gitlab/database/migration_helpers_spec.rb
spec/lib/gitlab/database/migration_helpers_spec.rb
+6
-2
No files found.
lib/gitlab/database/background_migration/batched_migration_runner.rb
View file @
6d666b21
...
@@ -54,17 +54,18 @@ module Gitlab
...
@@ -54,17 +54,18 @@ module Gitlab
def
finalize
(
job_class_name
,
table_name
,
column_name
,
job_arguments
)
def
finalize
(
job_class_name
,
table_name
,
column_name
,
job_arguments
)
migration
=
BatchedMigration
.
find_for_configuration
(
job_class_name
,
table_name
,
column_name
,
job_arguments
)
migration
=
BatchedMigration
.
find_for_configuration
(
job_class_name
,
table_name
,
column_name
,
job_arguments
)
if
migration
.
nil?
configuration
=
{
configuration
=
{
job_class_name:
job_class_name
,
job_class_name:
job_class_name
,
table_name:
table_name
,
table_name:
table_name
,
column_name:
column_name
,
column_name:
column_name
,
job_arguments:
job_arguments
job_arguments:
job_arguments
}
}
if
migration
.
nil?
Gitlab
::
AppLogger
.
warn
"Could not find batched background migration for the given configuration:
#{
configuration
}
"
Gitlab
::
AppLogger
.
warn
"Could not find batched background migration for the given configuration:
#{
configuration
}
"
elsif
migration
.
finished?
Gitlab
::
AppLogger
.
warn
"Batched background migration for the given configuration is already finished:
#{
configuration
}
"
else
else
return
if
migration
.
finished?
migration
.
finalizing!
migration
.
finalizing!
migration
.
batched_jobs
.
pending
.
each
{
|
job
|
migration_wrapper
.
perform
(
job
)
}
migration
.
batched_jobs
.
pending
.
each
{
|
job
|
migration_wrapper
.
perform
(
job
)
}
...
...
lib/gitlab/database/migration_helpers.rb
View file @
6d666b21
...
@@ -1106,7 +1106,11 @@ module Gitlab
...
@@ -1106,7 +1106,11 @@ module Gitlab
Gitlab
::
AppLogger
.
warn
"Could not find batched background migration for the given configuration:
#{
configuration
}
"
Gitlab
::
AppLogger
.
warn
"Could not find batched background migration for the given configuration:
#{
configuration
}
"
elsif
!
migration
.
finished?
elsif
!
migration
.
finished?
raise
"Expected batched background migration for the given configuration to be marked as 'finished', "
\
raise
"Expected batched background migration for the given configuration to be marked as 'finished', "
\
"but it is '
#{
migration
.
status
}
':
#{
configuration
}
"
"but it is '
#{
migration
.
status
}
':
#{
configuration
}
"
\
"
\n\n
"
\
"Finalize it manualy by running"
\
"
\n\n
"
\
"
\t
gitlab-rake gitlab:background_migrations:finalize[
#{
job_class_name
}
,
#{
table_name
}
,
#{
column_name
}
,'
#{
job_arguments
.
inspect
.
gsub
(
','
,
'\,'
)
}
']"
end
end
end
end
...
...
lib/tasks/gitlab/background_migrations.rake
0 → 100644
View file @
6d666b21
# frozen_string_literal: true
namespace
:gitlab
do
namespace
:background_migrations
do
task
:finalize
,
[
:job_class_name
,
:table_name
,
:column_name
,
:job_arguments
]
=>
:environment
do
|
_
,
args
|
[
:job_class_name
,
:table_name
,
:column_name
,
:job_arguments
].
each
do
|
argument
|
unless
args
[
argument
]
puts
"Must specify
#{
argument
}
as an argument"
.
color
(
:red
)
exit
1
end
end
Gitlab
::
Database
::
BackgroundMigration
::
BatchedMigrationRunner
.
finalize
(
args
[
:job_class_name
],
args
[
:table_name
],
args
[
:column_name
],
Gitlab
::
Json
.
parse
(
args
[
:job_arguments
])
)
puts
"Done."
.
color
(
:green
)
end
end
end
spec/lib/gitlab/database/background_migration/batched_migration_runner_spec.rb
View file @
6d666b21
...
@@ -381,6 +381,16 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigrationRunner do
...
@@ -381,6 +381,16 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigrationRunner do
.
with
(
'CopyColumnUsingBackgroundMigrationJob'
,
table_name
,
column_name
,
job_arguments
)
.
with
(
'CopyColumnUsingBackgroundMigrationJob'
,
table_name
,
column_name
,
job_arguments
)
.
and_return
(
batched_migration
)
.
and_return
(
batched_migration
)
configuration
=
{
job_class_name:
batched_migration
.
job_class_name
,
table_name:
table_name
.
to_sym
,
column_name:
column_name
.
to_sym
,
job_arguments:
job_arguments
}
expect
(
Gitlab
::
AppLogger
).
to
receive
(
:warn
)
.
with
(
"Batched background migration for the given configuration is already finished:
#{
configuration
}
"
)
expect
(
batched_migration
).
not_to
receive
(
:finalizing!
)
expect
(
batched_migration
).
not_to
receive
(
:finalizing!
)
runner
.
finalize
(
runner
.
finalize
(
...
...
spec/lib/gitlab/database/migration_helpers_spec.rb
View file @
6d666b21
...
@@ -2007,7 +2007,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
...
@@ -2007,7 +2007,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
job_class_name:
'CopyColumnUsingBackgroundMigrationJob'
,
job_class_name:
'CopyColumnUsingBackgroundMigrationJob'
,
table_name: :events
,
table_name: :events
,
column_name: :id
,
column_name: :id
,
job_arguments:
[[
:id
],
[
:id_convert_to_bigint
]]
job_arguments:
[[
"id"
],
[
"id_convert_to_bigint"
]]
}
}
end
end
...
@@ -2017,7 +2017,11 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
...
@@ -2017,7 +2017,11 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
create
(
:batched_background_migration
,
configuration
.
merge
(
status: :active
))
create
(
:batched_background_migration
,
configuration
.
merge
(
status: :active
))
expect
{
ensure_batched_background_migration_is_finished
}
expect
{
ensure_batched_background_migration_is_finished
}
.
to
raise_error
"Expected batched background migration for the given configuration to be marked as 'finished', but it is 'active':
#{
configuration
}
"
.
to
raise_error
"Expected batched background migration for the given configuration to be marked as 'finished', but it is 'active':
#{
configuration
}
"
\
"
\n\n
"
\
"Finalize it manualy by running"
\
"
\n\n
"
\
"
\t
gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,events,id,'[[
\"
id
\"
]
\\
, [
\"
id_convert_to_bigint
\"
]]']"
end
end
it
'does not raise error when migration exists and is marked as finished'
do
it
'does not raise error when migration exists and is marked as finished'
do
...
...
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