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
32f09dc4
Commit
32f09dc4
authored
Nov 10, 2020
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter non-existing Project IDs while populating `has_vulnerabilities`
parent
2e20097d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
6 deletions
+12
-6
lib/gitlab/background_migration/populate_has_vulnerabilities.rb
...tlab/background_migration/populate_has_vulnerabilities.rb
+5
-6
spec/lib/gitlab/background_migration/populate_has_vulnerabilities_spec.rb
...background_migration/populate_has_vulnerabilities_spec.rb
+7
-0
No files found.
lib/gitlab/background_migration/populate_has_vulnerabilities.rb
View file @
32f09dc4
...
...
@@ -9,10 +9,12 @@ module Gitlab
self
.
table_name
=
'project_settings'
UPSERT_SQL
=
<<~
SQL
WITH upsert_data (project_id, has_vulnerabilities, created_at, updated_at) AS (
SELECT projects.id, true, current_timestamp, current_timestamp FROM projects WHERE projects.id IN (%{project_ids})
)
INSERT INTO project_settings
(project_id, has_vulnerabilities, created_at, updated_at)
VALUES
%{values}
(SELECT * FROM upsert_data)
ON CONFLICT (project_id)
DO UPDATE SET
has_vulnerabilities = true,
...
...
@@ -20,10 +22,7 @@ module Gitlab
SQL
def
self
.
upsert_for
(
project_ids
)
timestamp
=
connection
.
quote
(
Time
.
now
)
values
=
project_ids
.
map
{
|
project_id
|
"(
#{
project_id
}
, true,
#{
timestamp
}
,
#{
timestamp
}
)"
}.
join
(
', '
)
connection
.
execute
(
UPSERT_SQL
%
{
values:
values
})
connection
.
execute
(
UPSERT_SQL
%
{
project_ids:
project_ids
.
join
(
', '
)
})
end
end
...
...
spec/lib/gitlab/background_migration/populate_has_vulnerabilities_spec.rb
View file @
32f09dc4
...
...
@@ -39,6 +39,13 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateHasVulnerabilities, schema:
count:
2
)
end
context
'when non-existing project_id is given'
do
it
'populates only for the existing projects'
do
expect
{
subject
.
perform
(
project_1
.
id
,
0
,
project_3
.
id
)
}.
to
change
{
project_settings
.
count
}.
from
(
1
).
to
(
2
)
.
and
change
{
project_settings
.
where
(
has_vulnerabilities:
true
).
count
}.
from
(
0
).
to
(
2
)
end
end
context
'when an error happens'
do
before
do
allow
(
described_class
::
ProjectSetting
).
to
receive
(
:upsert_for
).
and_raise
(
'foo'
)
...
...
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