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
ac185048
Commit
ac185048
authored
Nov 03, 2020
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create post deploy migration to populate has_vulnerabilities
parent
1a043e6f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
0 deletions
+61
-0
db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb
...e/20201103192526_schedule_populate_has_vulnerabilities.rb
+24
-0
db/schema_migrations/20201103192526
db/schema_migrations/20201103192526
+1
-0
spec/migrations/schedule_populate_has_vulnerabilities_spec.rb
.../migrations/schedule_populate_has_vulnerabilities_spec.rb
+36
-0
No files found.
db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb
0 → 100644
View file @
ac185048
# frozen_string_literal: true
class
SchedulePopulateHasVulnerabilities
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
BATCH_SIZE
=
1_000
DELAY_INTERVAL
=
2
.
minutes
MIGRATION_CLASS
=
'PopulateHasVulnerabilities'
disable_ddl_transaction!
def
up
Gitlab
::
BackgroundMigration
::
PopulateHasVulnerabilities
::
Vulnerability
.
distinct
.
each_batch
(
of:
BATCH_SIZE
,
column: :project_id
)
do
|
batch
,
index
|
project_ids
=
batch
.
pluck
(
:project_id
)
migrate_in
(
index
*
DELAY_INTERVAL
,
MIGRATION_CLASS
,
project_ids
)
end
end
def
down
# no-op
end
end
db/schema_migrations/20201103192526
0 → 100644
View file @
ac185048
bb137c3a41a40e740f8ae65b43d7f9218f52d6d5eaf53c8a64b3336a8f16141b
\ No newline at end of file
spec/migrations/schedule_populate_has_vulnerabilities_spec.rb
0 → 100644
View file @
ac185048
# frozen_string_literal: true
require
'spec_helper'
require_migration!
RSpec
.
describe
SchedulePopulateHasVulnerabilities
do
let
(
:users
)
{
table
(
:users
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:vulnerabilities
)
{
table
(
:vulnerabilities
)
}
let
(
:user
)
{
users
.
create!
(
name:
'test'
,
email:
'test@example.com'
,
projects_limit:
5
)
}
let
(
:namespace
)
{
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org'
)
}
let
(
:vulnerability_base_params
)
{
{
title:
'title'
,
state:
2
,
severity:
0
,
confidence:
5
,
report_type:
2
,
author_id:
user
.
id
}
}
let!
(
:project_1
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
,
name:
'foo_1'
)
}
let!
(
:project_2
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
,
name:
'foo_2'
)
}
let!
(
:project_3
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
,
name:
'foo_3'
)
}
around
do
|
example
|
freeze_time
{
Sidekiq
::
Testing
.
fake!
{
example
.
run
}
}
end
before
do
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
1
)
vulnerabilities
.
create!
(
vulnerability_base_params
.
merge
(
project_id:
project_1
.
id
))
vulnerabilities
.
create!
(
vulnerability_base_params
.
merge
(
project_id:
project_3
.
id
))
end
it
'schedules the background jobs'
,
:aggregate_failures
do
migrate!
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
be
(
2
)
expect
(
described_class
::
MIGRATION_CLASS
).
to
be_scheduled_delayed_migration
(
2
.
minutes
,
project_1
.
id
)
expect
(
described_class
::
MIGRATION_CLASS
).
to
be_scheduled_delayed_migration
(
4
.
minutes
,
project_3
.
id
)
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