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
377b6c6c
Commit
377b6c6c
authored
Jun 08, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add post migration for failed imported snippet repositories
parent
00477e9d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
0 deletions
+105
-0
changelogs/unreleased/fj-backfill-imported-snippet-repositories.yml
.../unreleased/fj-backfill-imported-snippet-repositories.yml
+5
-0
db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb
.../20200608072931_backfill_imported_snippet_repositories.rb
+47
-0
db/structure.sql
db/structure.sql
+1
-0
spec/migrations/backfill_imported_snippet_repositories_spec.rb
...migrations/backfill_imported_snippet_repositories_spec.rb
+52
-0
No files found.
changelogs/unreleased/fj-backfill-imported-snippet-repositories.yml
0 → 100644
View file @
377b6c6c
---
title
:
Backfill failed imported snippet repositories
merge_request
:
34052
author
:
type
:
other
db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb
0 → 100644
View file @
377b6c6c
# frozen_string_literal: true
class
BackfillImportedSnippetRepositories
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DELAY_INTERVAL
=
2
.
minutes
.
to_i
BATCH_SIZE
=
200
MIGRATION
=
'BackfillSnippetRepositories'
disable_ddl_transaction!
class
Snippet
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'snippets'
self
.
inheritance_column
=
:_type_disabled
end
class
SnippetRepository
<
ActiveRecord
::
Base
self
.
table_name
=
'snippet_repositories'
end
def
up
index
=
1
Snippet
.
select
(
:id
).
where
.
not
(
id:
SnippetRepository
.
select
(
:snippet_id
)).
each_batch
(
of:
BATCH_SIZE
,
column:
'id'
)
do
|
batch
|
split_in_consecutive_batches
(
batch
).
each
do
|
ids_batch
|
migrate_in
(
index
*
DELAY_INTERVAL
,
MIGRATION
,
[
ids_batch
.
first
,
ids_batch
.
last
])
index
+=
1
end
end
end
def
down
# no-op
end
private
def
split_in_consecutive_batches
(
relation
)
ids
=
relation
.
pluck
(
:id
)
(
ids
.
first
..
ids
.
last
).
to_a
.
split
{
|
i
|
!
ids
.
include?
(
i
)
}.
select
(
&
:present?
)
end
end
db/structure.sql
View file @
377b6c6c
...
...
@@ -13886,6 +13886,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200604145731
20200604174544
20200604174558
20200608072931
20200608075553
20200609002841
\
.
...
...
spec/migrations/backfill_imported_snippet_repositories_spec.rb
0 → 100644
View file @
377b6c6c
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200608072931_backfill_imported_snippet_repositories.rb'
)
describe
BackfillImportedSnippetRepositories
do
let
(
:users
)
{
table
(
:users
)
}
let
(
:snippets
)
{
table
(
:snippets
)
}
let
(
:user
)
{
users
.
create
(
id:
1
,
email:
'user@example.com'
,
projects_limit:
10
,
username:
'test'
,
name:
'Test'
,
state:
'active'
)
}
def
create_snippet
(
id
)
params
=
{
id:
id
,
type:
'PersonalSnippet'
,
author_id:
user
.
id
,
file_name:
'foo'
,
content:
'bar'
}
snippets
.
create!
(
params
)
end
it
'correctly schedules background migrations'
do
create_snippet
(
1
)
create_snippet
(
2
)
create_snippet
(
3
)
create_snippet
(
5
)
create_snippet
(
7
)
create_snippet
(
8
)
create_snippet
(
10
)
Sidekiq
::
Testing
.
fake!
do
Timecop
.
freeze
do
migrate!
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
2
.
minutes
,
1
,
3
)
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
4
.
minutes
,
5
,
5
)
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
6
.
minutes
,
7
,
8
)
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
8
.
minutes
,
10
,
10
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
(
4
)
end
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