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
cac12b17
Commit
cac12b17
authored
Sep 10, 2020
by
Mike Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure filled external_diff_store on MR diffs
parent
ceb620bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
0 deletions
+72
-0
db/post_migrate/20200910170908_ensure_filled_external_diff_store_on_merge_request_diffs.rb
...sure_filled_external_diff_store_on_merge_request_diffs.rb
+31
-0
db/schema_migrations/20200910170908
db/schema_migrations/20200910170908
+1
-0
spec/migrations/ensure_filled_external_diff_store_on_merge_request_diffs_spec.rb
...filled_external_diff_store_on_merge_request_diffs_spec.rb
+40
-0
No files found.
db/post_migrate/20200910170908_ensure_filled_external_diff_store_on_merge_request_diffs.rb
0 → 100644
View file @
cac12b17
# frozen_string_literal: true
class
EnsureFilledExternalDiffStoreOnMergeRequestDiffs
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
BACKGROUND_MIGRATION_CLASS
=
'SetNullExternalDiffStoreToLocalValue'
BATCH_SIZE
=
5_000
LOCAL_STORE
=
1
# equal to ObjectStorage::Store::LOCAL
DOWNTIME
=
false
disable_ddl_transaction!
class
MergeRequestDiff
<
ActiveRecord
::
Base
self
.
table_name
=
'merge_request_diffs'
include
::
EachBatch
end
def
up
Gitlab
::
BackgroundMigration
.
steal
(
BACKGROUND_MIGRATION_CLASS
)
# Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low.
MergeRequestDiff
.
where
(
external_diff_store:
nil
).
each_batch
(
of:
BATCH_SIZE
)
do
|
batch
,
index
|
batch
.
update_all
(
external_diff_store:
LOCAL_STORE
)
end
end
def
down
# no-op
end
end
db/schema_migrations/20200910170908
0 → 100644
View file @
cac12b17
de13fed042f6e3d2a6612a77acebf168c8beddab5796b96f2d77886dea431ceb
\ No newline at end of file
spec/migrations/ensure_filled_external_diff_store_on_merge_request_diffs_spec.rb
0 → 100644
View file @
cac12b17
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200910170908_ensure_filled_external_diff_store_on_merge_request_diffs.rb'
)
RSpec
.
describe
EnsureFilledExternalDiffStoreOnMergeRequestDiffs
,
schema:
20200908095446
do
let!
(
:merge_request_diffs
)
{
table
(
:merge_request_diffs
)
}
let!
(
:merge_requests
)
{
table
(
:merge_requests
)
}
let!
(
:namespaces
)
{
table
(
:namespaces
)
}
let!
(
:projects
)
{
table
(
:projects
)
}
let!
(
:namespace
)
{
namespaces
.
create!
(
name:
'foo'
,
path:
'foo'
)
}
let!
(
:project
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
)
}
let!
(
:merge_request
)
{
merge_requests
.
create!
(
source_branch:
'x'
,
target_branch:
'master'
,
target_project_id:
project
.
id
)
}
before
do
constraint_name
=
'check_93ee616ac9'
# In order to insert a row with a NULL to fill.
ActiveRecord
::
Base
.
connection
.
execute
"ALTER TABLE merge_request_diffs DROP CONSTRAINT
#{
constraint_name
}
"
@external_diff_store_1
=
merge_request_diffs
.
create!
(
external_diff_store:
1
,
merge_request_id:
merge_request
.
id
)
@external_diff_store_2
=
merge_request_diffs
.
create!
(
external_diff_store:
2
,
merge_request_id:
merge_request
.
id
)
@external_diff_store_nil
=
merge_request_diffs
.
create!
(
external_diff_store:
nil
,
merge_request_id:
merge_request
.
id
)
# revert DB structure
ActiveRecord
::
Base
.
connection
.
execute
"ALTER TABLE merge_request_diffs ADD CONSTRAINT
#{
constraint_name
}
CHECK ((external_diff_store IS NOT NULL)) NOT VALID"
end
it
'correctly migrates nil external_diff_store to 1'
do
migrate!
@external_diff_store_1
.
reload
@external_diff_store_2
.
reload
@external_diff_store_nil
.
reload
expect
(
@external_diff_store_1
.
external_diff_store
).
to
eq
(
1
)
# unchanged
expect
(
@external_diff_store_2
.
external_diff_store
).
to
eq
(
2
)
# unchanged
expect
(
@external_diff_store_nil
.
external_diff_store
).
to
eq
(
1
)
# nil => 1
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