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
d10601ba
Commit
d10601ba
authored
Jun 17, 2021
by
Krasimir Angelov
Committed by
Mikołaj Wawrzyniak
Jun 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix batched migrations using legacy job arguments
parent
fc90d5e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
0 deletions
+96
-0
db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb
...234935_fix_batched_migrations_old_format_job_arguments.rb
+32
-0
db/schema_migrations/20210615234935
db/schema_migrations/20210615234935
+1
-0
spec/migrations/fix_batched_migrations_old_format_job_arguments_spec.rb
...s/fix_batched_migrations_old_format_job_arguments_spec.rb
+63
-0
No files found.
db/post_migrate/20210615234935_fix_batched_migrations_old_format_job_arguments.rb
0 → 100644
View file @
d10601ba
# frozen_string_literal: true
class
FixBatchedMigrationsOldFormatJobArguments
<
ActiveRecord
::
Migration
[
6.1
]
class
BatchedMigration
<
ActiveRecord
::
Base
self
.
table_name
=
'batched_background_migrations'
end
def
up
# rubocop:disable Style/WordArray
[
[
'events'
,
'id'
,
[
'id'
,
'id_convert_to_bigint'
],
[[
'id'
],
[
'id_convert_to_bigint'
]]],
[
'push_event_payloads'
,
'event_id'
,
[
'event_id'
,
'event_id_convert_to_bigint'
],
[[
'event_id'
],
[
'event_id_convert_to_bigint'
]]]
].
each
do
|
table_name
,
column_name
,
legacy_job_arguments
,
current_job_arguments
|
base_scope
=
BatchedMigration
.
where
(
job_class_name:
'CopyColumnUsingBackgroundMigrationJob'
,
table_name:
table_name
,
column_name:
column_name
)
# rubocop:enable Style/WordArray
# rubocop:disable Rails/WhereEquals
base_scope
.
where
(
'job_arguments = ?'
,
legacy_job_arguments
.
to_json
)
.
where
(
'NOT EXISTS (?)'
,
base_scope
.
select
(
'1'
).
where
(
'job_arguments = ?'
,
current_job_arguments
.
to_json
))
.
update_all
(
job_arguments:
current_job_arguments
)
# rubocop:enable Rails/WhereEquals
end
end
def
down
# No-op, there is no way to know were the existing record migrated from
# legacy job arguments, or were using the current format from the start.
# There is no reason to go back anyway.
end
end
db/schema_migrations/20210615234935
0 → 100644
View file @
d10601ba
205336e95a6e3c9fa8c56fa67e66ef3023ba8c6cd4e6f3599160b74b3fbfaa3c
\ No newline at end of file
spec/migrations/fix_batched_migrations_old_format_job_arguments_spec.rb
0 → 100644
View file @
d10601ba
# frozen_string_literal: true
require
'spec_helper'
require_migration!
# rubocop:disable Style/WordArray
RSpec
.
describe
FixBatchedMigrationsOldFormatJobArguments
do
let
(
:batched_background_migrations
)
{
table
(
:batched_background_migrations
)
}
context
'when migrations with legacy job arguments exists'
do
it
'updates job arguments to current format'
do
legacy_events_migration
=
create_batched_migration
(
'events'
,
'id'
,
[
'id'
,
'id_convert_to_bigint'
])
legacy_push_event_payloads_migration
=
create_batched_migration
(
'push_event_payloads'
,
'event_id'
,
[
'event_id'
,
'event_id_convert_to_bigint'
])
migrate!
expect
(
legacy_events_migration
.
reload
.
job_arguments
).
to
eq
([[
'id'
],
[
'id_convert_to_bigint'
]])
expect
(
legacy_push_event_payloads_migration
.
reload
.
job_arguments
).
to
eq
([[
'event_id'
],
[
'event_id_convert_to_bigint'
]])
end
end
context
'when only migrations with current job arguments exists'
do
it
'updates nothing'
do
events_migration
=
create_batched_migration
(
'events'
,
'id'
,
[[
'id'
],
[
'id_convert_to_bigint'
]])
push_event_payloads_migration
=
create_batched_migration
(
'push_event_payloads'
,
'event_id'
,
[[
'event_id'
],
[
'event_id_convert_to_bigint'
]])
migrate!
expect
(
events_migration
.
reload
.
job_arguments
).
to
eq
([[
'id'
],
[
'id_convert_to_bigint'
]])
expect
(
push_event_payloads_migration
.
reload
.
job_arguments
).
to
eq
([[
'event_id'
],
[
'event_id_convert_to_bigint'
]])
end
end
context
'when migrations with both legacy and current job arguments exist'
do
it
'updates nothing'
do
legacy_events_migration
=
create_batched_migration
(
'events'
,
'id'
,
[
'id'
,
'id_convert_to_bigint'
])
events_migration
=
create_batched_migration
(
'events'
,
'id'
,
[[
'id'
],
[
'id_convert_to_bigint'
]])
legacy_push_event_payloads_migration
=
create_batched_migration
(
'push_event_payloads'
,
'event_id'
,
[
'event_id'
,
'event_id_convert_to_bigint'
])
push_event_payloads_migration
=
create_batched_migration
(
'push_event_payloads'
,
'event_id'
,
[[
'event_id'
],
[
'event_id_convert_to_bigint'
]])
migrate!
expect
(
legacy_events_migration
.
reload
.
job_arguments
).
to
eq
([
'id'
,
'id_convert_to_bigint'
])
expect
(
events_migration
.
reload
.
job_arguments
).
to
eq
([[
'id'
],
[
'id_convert_to_bigint'
]])
expect
(
legacy_push_event_payloads_migration
.
reload
.
job_arguments
).
to
eq
([
'event_id'
,
'event_id_convert_to_bigint'
])
expect
(
push_event_payloads_migration
.
reload
.
job_arguments
).
to
eq
([[
'event_id'
],
[
'event_id_convert_to_bigint'
]])
end
end
def
create_batched_migration
(
table_name
,
column_name
,
job_arguments
)
batched_background_migrations
.
create!
(
max_value:
10
,
batch_size:
10
,
sub_batch_size:
10
,
interval:
1
,
job_class_name:
'CopyColumnUsingBackgroundMigrationJob'
,
table_name:
table_name
,
column_name:
column_name
,
job_arguments:
job_arguments
)
end
end
# rubocop:enable Style/WordArray
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