Add severity level to compliance violations table
What does this MR do and why?
This MR adds the severity level to the compliance violations table. The usage of this table is behind the :compliance_violations_graphql_type
feature flag. The service which creates the violations will not run unless the flag is enabled.
It also updates the saving process to make sure the severity is stored when MR's are merged.
Output of `db:check-migrations` job
$ scripts/validate_migration_schema
$ git diff --name-only --diff-filter=A master -- db/migrate db/post_migrate
db/migrate/20220131135725_add_severity_level_to_merge_requests_compliance_violations.rb
$ scripts/db_tasks db:migrate:down VERSION=20220131135725
== 20220131135725 AddSeverityLevelToMergeRequestsComplianceViolations: reverting
-- remove_column(:merge_requests_compliance_violations, :severity_level, :integer, {:limit=>2, :null=>false, :default=>0})
-> 0.0015s
== 20220131135725 AddSeverityLevelToMergeRequestsComplianceViolations: reverted (0.0347s)
$ scripts/db_tasks db:schema:dump
$ git diff master -- db/structure.sql
$ scripts/db_tasks db:migrate
== 20220131135725 AddSeverityLevelToMergeRequestsComplianceViolations: migrating
-- add_column(:merge_requests_compliance_violations, :severity_level, :integer, {:limit=>2, :null=>false, :default=>0})
-> 0.0022s
== 20220131135725 AddSeverityLevelToMergeRequestsComplianceViolations: migrated (0.0023s)
$ scripts/db_tasks db:schema:dump
$ git diff -- db/structure.sql
$ git add -A -n db/schema_migrations
How to set up and validate locally
- Enable the feature flag
compliance_violations_graphql_type
:echo "Feature.enable(:compliance_violations_graphql_type)" | bundle exec rails c
- Run the migration:
bundle exec rails db:migrate
- Go to a projects general settings and make sure
Prevent approval by author.
is unticked under theMerge request approvals
section - Edit a file in the project and create a new merge request
- Use the merge requests author to approve the merge request and then merge it
- Wait for merging to be completed
- Check the
merge_request_compliance_violations
table to see rows with the correct severity levels on the violations- Use a database GUI
- In your terminal enter
gdk psql
and then run the following query:SELECT * FROM merge_requests_compliance_violations;
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #351577 (closed)
Edited by Robert Hunt