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
0a5a7f13
Commit
0a5a7f13
authored
Aug 23, 2021
by
Zamir Martins
Committed by
Andreas Brandl
Aug 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add default value to vulnerabilities_allowed column
parent
4524225c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
1 deletion
+61
-1
db/migrate/20210818220234_add_default_project_approval_rules_vuln_allowed.rb
...220234_add_default_project_approval_rules_vuln_allowed.rb
+24
-0
db/schema_migrations/20210818220234
db/schema_migrations/20210818220234
+1
-0
db/structure.sql
db/structure.sql
+1
-1
spec/migrations/add_default_project_approval_rules_vuln_allowed_spec.rb
...s/add_default_project_approval_rules_vuln_allowed_spec.rb
+35
-0
No files found.
db/migrate/20210818220234_add_default_project_approval_rules_vuln_allowed.rb
0 → 100644
View file @
0a5a7f13
# frozen_string_literal: true
class
AddDefaultProjectApprovalRulesVulnAllowed
<
ActiveRecord
::
Migration
[
6.1
]
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
DEFAULT_VALUE
=
0
def
up
change_column_default
:approval_project_rules
,
:vulnerabilities_allowed
,
DEFAULT_VALUE
update_column_in_batches
(
:approval_project_rules
,
:vulnerabilities_allowed
,
DEFAULT_VALUE
)
do
|
table
,
query
|
query
.
where
(
table
[
:vulnerabilities_allowed
].
eq
(
nil
))
end
change_column_null
:approval_project_rules
,
:vulnerabilities_allowed
,
false
end
def
down
change_column_default
:approval_project_rules
,
:vulnerabilities_allowed
,
nil
change_column_null
:approval_project_rules
,
:vulnerabilities_allowed
,
true
end
end
db/schema_migrations/20210818220234
0 → 100644
View file @
0a5a7f13
8d247218468ad383d1a8a2dc67d5e7e67ddad2a33a38203a41e49c4c018adc7e
\ No newline at end of file
db/structure.sql
View file @
0a5a7f13
...
@@ -9746,7 +9746,7 @@ CREATE TABLE approval_project_rules (
...
@@ -9746,7 +9746,7 @@ CREATE TABLE approval_project_rules (
name character varying NOT NULL,
name character varying NOT NULL,
rule_type smallint DEFAULT 0 NOT NULL,
rule_type smallint DEFAULT 0 NOT NULL,
scanners text[],
scanners text[],
vulnerabilities_allowed smallint,
vulnerabilities_allowed smallint
DEFAULT 0 NOT NULL
,
severity_levels text[] DEFAULT '{}'::text[] NOT NULL
severity_levels text[] DEFAULT '{}'::text[] NOT NULL
);
);
spec/migrations/add_default_project_approval_rules_vuln_allowed_spec.rb
0 → 100644
View file @
0a5a7f13
# frozen_string_literal: true
require
'spec_helper'
require_migration!
RSpec
.
describe
AddDefaultProjectApprovalRulesVulnAllowed
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:namespace
)
{
namespaces
.
create!
(
name:
'namespace'
,
path:
'namespace'
)
}
let
(
:project
)
{
projects
.
create!
(
name:
'project'
,
path:
'project'
,
namespace_id:
namespace
.
id
)
}
let
(
:approval_project_rules
)
{
table
(
:approval_project_rules
)
}
it
'updates records when vulnerabilities_allowed is nil'
do
records_to_migrate
=
10
records_to_migrate
.
times
do
|
i
|
approval_project_rules
.
create!
(
name:
"rule
#{
i
}
"
,
project_id:
project
.
id
)
end
expect
{
migrate!
}
.
to
change
{
approval_project_rules
.
where
(
vulnerabilities_allowed:
nil
).
count
}
.
from
(
records_to_migrate
)
.
to
(
0
)
end
it
'defaults vulnerabilities_allowed to 0'
do
approval_project_rule
=
approval_project_rules
.
create!
(
name:
"new rule"
,
project_id:
project
.
id
)
expect
(
approval_project_rule
.
vulnerabilities_allowed
).
to
be_nil
migrate!
expect
(
approval_project_rule
.
reload
.
vulnerabilities_allowed
).
to
eq
(
0
)
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