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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
16116bb1
Commit
16116bb1
authored
Nov 05, 2018
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migration to steal FillStoreUpload
parent
149b6327
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
db/post_migrate/20181105201455_steal_fill_store_upload.rb
db/post_migrate/20181105201455_steal_fill_store_upload.rb
+31
-0
spec/migrations/steal_fill_store_upload_spec.rb
spec/migrations/steal_fill_store_upload_spec.rb
+40
-0
No files found.
db/post_migrate/20181105201455_steal_fill_store_upload.rb
0 → 100644
View file @
16116bb1
# frozen_string_literal: true
class
StealFillStoreUpload
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
BATCH_SIZE
=
10_000
disable_ddl_transaction!
class
Upload
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'uploads'
self
.
inheritance_column
=
:_type_disabled
# Disable STI
end
def
up
Gitlab
::
BackgroundMigration
.
steal
(
'FillStoreUpload'
)
Upload
.
where
(
store:
nil
).
each_batch
(
of:
BATCH_SIZE
)
do
|
batch
|
range
=
batch
.
pluck
(
'MIN(id)'
,
'MAX(id)'
).
first
Gitlab
::
BackgroundMigration
::
FillStoreUpload
.
new
.
perform
(
*
range
)
end
end
def
down
# noop
end
end
spec/migrations/steal_fill_store_upload_spec.rb
0 → 100644
View file @
16116bb1
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20181105201455_steal_fill_store_upload.rb'
)
describe
StealFillStoreUpload
,
:migration
do
let
(
:uploads
)
{
table
(
:uploads
)
}
describe
'#up'
do
it
'steals the FillStoreUpload background migration'
do
expect
(
Gitlab
::
BackgroundMigration
).
to
receive
(
:steal
).
with
(
'FillStoreUpload'
).
and_call_original
migrate!
end
it
'does not run migration if not needed'
do
uploads
.
create
(
size:
100
.
kilobytes
,
uploader:
'AvatarUploader'
,
path:
'uploads/-/system/avatar.jpg'
,
store:
1
)
expect_any_instance_of
(
Gitlab
::
BackgroundMigration
::
FillStoreUpload
).
not_to
receive
(
:perform
)
migrate!
end
it
'ensures all rows are migrated'
do
uploads
.
create
(
size:
100
.
kilobytes
,
uploader:
'AvatarUploader'
,
path:
'uploads/-/system/avatar.jpg'
,
store:
nil
)
expect_any_instance_of
(
Gitlab
::
BackgroundMigration
::
FillStoreUpload
).
to
receive
(
:perform
).
and_call_original
expect
do
migrate!
end
.
to
change
{
uploads
.
where
(
store:
nil
).
count
}.
from
(
1
).
to
(
0
)
end
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