Commit 614172fc authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '239177_add_checksum_into_vulnerability_remediations' into 'master'

Add checksum into vulnerability_remediations table

See merge request gitlab-org/gitlab!48165
parents 7385886b c1ebe479
---
title: Add `checksum` column into the `vulnerability_remediations` table
merge_request: 48165
author:
type: changed
# frozen_string_literal: true
class AddChecksumIntoVulnerabilityRemediations < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :vulnerability_remediations, :checksum, :binary, null: false, comment: 'Stores the SHA256 checksum of the attached diff file' # rubocop:disable Rails/NotNullColumn
add_index :vulnerability_remediations, :checksum, unique: true # rubocop:disable Migration/AddIndex (Table is empty)
end
end
5abd2cfdf96b493f8d3ecc857f850acb95e3ea30307a72c2e6f20c5feff8f5e7
\ No newline at end of file
......@@ -17357,10 +17357,13 @@ CREATE TABLE vulnerability_remediations (
file_store smallint,
summary text NOT NULL,
file text NOT NULL,
checksum bytea NOT NULL,
CONSTRAINT check_ac0ccabff3 CHECK ((char_length(summary) <= 200)),
CONSTRAINT check_fe3325e3ba CHECK ((char_length(file) <= 255))
);
COMMENT ON COLUMN vulnerability_remediations.checksum IS 'Stores the SHA256 checksum of the attached diff file';
CREATE SEQUENCE vulnerability_remediations_id_seq
START WITH 1
INCREMENT BY 1
......@@ -22334,6 +22337,8 @@ CREATE UNIQUE INDEX index_vulnerability_occurrences_on_uuid ON vulnerability_occ
CREATE INDEX index_vulnerability_occurrences_on_vulnerability_id ON vulnerability_occurrences USING btree (vulnerability_id);
CREATE UNIQUE INDEX index_vulnerability_remediations_on_checksum ON vulnerability_remediations USING btree (checksum);
CREATE UNIQUE INDEX index_vulnerability_scanners_on_project_id_and_external_id ON vulnerability_scanners USING btree (project_id, external_id);
CREATE INDEX index_vulnerability_statistics_on_letter_grade ON vulnerability_statistics USING btree (letter_grade);
......
......@@ -3,9 +3,12 @@
module Vulnerabilities
class Remediation < ApplicationRecord
include FileStoreMounter
include ShaAttribute
self.table_name = 'vulnerability_remediations'
sha_attribute :checksum
has_many :finding_remediations, class_name: 'Vulnerabilities::FindingRemediation', inverse_of: :remediation, foreign_key: 'vulnerability_remediation_id'
has_many :findings, through: :finding_remediations
......@@ -13,5 +16,6 @@ module Vulnerabilities
validates :summary, presence: true, length: { maximum: 200 }
validates :file, presence: true
validates :checksum, presence: true
end
end
......@@ -8,5 +8,6 @@ RSpec.describe Vulnerabilities::Remediation do
it { is_expected.to validate_presence_of(:summary) }
it { is_expected.to validate_presence_of(:file) }
it { is_expected.to validate_presence_of(:checksum) }
it { is_expected.to validate_length_of(:summary).is_at_most(200) }
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment