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
8a151b2e
Commit
8a151b2e
authored
Nov 19, 2020
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create migration to schedule re-population of historical stats
parent
4777f8e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
0 deletions
+68
-0
db/post_migrate/20201119092319_schedule_repopulate_historical_vulnerability_statistics.rb
...chedule_repopulate_historical_vulnerability_statistics.rb
+31
-0
db/schema_migrations/20201119092319
db/schema_migrations/20201119092319
+1
-0
spec/migrations/schedule_repopulate_historical_vulnerability_statistics_spec.rb
...le_repopulate_historical_vulnerability_statistics_spec.rb
+36
-0
No files found.
db/post_migrate/20201119092319_schedule_repopulate_historical_vulnerability_statistics.rb
0 → 100644
View file @
8a151b2e
# frozen_string_literal: true
class
ScheduleRepopulateHistoricalVulnerabilityStatistics
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
BATCH_SIZE
=
50
DELAY_INTERVAL
=
5
.
minutes
MIGRATION_CLASS
=
'PopulateVulnerabilityHistoricalStatistics'
DAY_COUNT
=
365
disable_ddl_transaction!
class
ProjectSetting
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'project_settings'
scope
:has_vulnerabilities
,
->
{
where
(
'has_vulnerabilities IS TRUE'
)
}
end
def
up
ProjectSetting
.
has_vulnerabilities
.
each_batch
(
of:
BATCH_SIZE
)
do
|
batch
,
index
|
migrate_in
(
index
*
DELAY_INTERVAL
,
MIGRATION_CLASS
,
[
batch
.
pluck
(
:project_id
),
DAY_COUNT
])
end
end
def
down
# no-op
end
end
db/schema_migrations/20201119092319
0 → 100644
View file @
8a151b2e
9ff8ddefff1df81f1eac2ccfc6f3019bb77a6129280e799c0abe54f51e09277a
\ No newline at end of file
spec/migrations/schedule_repopulate_historical_vulnerability_statistics_spec.rb
0 → 100644
View file @
8a151b2e
# frozen_string_literal: true
require
'spec_helper'
require_migration!
RSpec
.
describe
ScheduleRepopulateHistoricalVulnerabilityStatistics
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:project_settings
)
{
table
(
:project_settings
)
}
let
(
:namespace
)
{
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org'
)
}
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'
)
}
let!
(
:project_4
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
,
name:
'foo_4'
)
}
around
do
|
example
|
freeze_time
{
Sidekiq
::
Testing
.
fake!
{
example
.
run
}
}
end
before
do
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
1
)
project_settings
.
create!
(
project_id:
project_1
.
id
,
has_vulnerabilities:
true
)
project_settings
.
create!
(
project_id:
project_2
.
id
,
has_vulnerabilities:
false
)
project_settings
.
create!
(
project_id:
project_4
.
id
,
has_vulnerabilities:
true
)
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
(
described_class
::
DELAY_INTERVAL
,
[
project_1
.
id
],
described_class
::
DAY_COUNT
)
expect
(
described_class
::
MIGRATION_CLASS
).
to
be_scheduled_delayed_migration
(
2
*
described_class
::
DELAY_INTERVAL
,
[
project_4
.
id
],
described_class
::
DAY_COUNT
)
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