Commit 6ebaa0d1 authored by Jonathan Schafer's avatar Jonathan Schafer

Add FindingEvidenceRequest and table

Includes database migration and schema
parent fd3248f6
---
title: Add VulnerabiltyFindingEvidenceRequest model
merge_request: 59539
author:
type: changed
# frozen_string_literal: true
class CreateVulnerabilityFindingEvidenceRequests < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
create_table_with_constraints :vulnerability_finding_evidence_requests do |t|
t.timestamps_with_timezone null: false
t.references :vulnerability_finding_evidences, index: { name: 'finding_evidence_requests_on_finding_evidence_id' }, null: false, foreign_key: { on_delete: :cascade }
t.text :method
t.text :url
t.text_limit :method, 32
t.text_limit :url, 2048
end
end
def down
with_lock_retries do
drop_table :vulnerability_finding_evidence_requests
end
end
end
06d33e4eb99e46cb6caf71916e5c93c4b7eb9fe73152841c7c41d5e157ec339e
\ No newline at end of file
......@@ -18540,6 +18540,26 @@ CREATE SEQUENCE vulnerability_feedback_id_seq
ALTER SEQUENCE vulnerability_feedback_id_seq OWNED BY vulnerability_feedback.id;
CREATE TABLE vulnerability_finding_evidence_requests (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
vulnerability_finding_evidences_id bigint NOT NULL,
method text,
url text,
CONSTRAINT check_8152fbb236 CHECK ((char_length(url) <= 2048)),
CONSTRAINT check_d9d11300f4 CHECK ((char_length(method) <= 32))
);
CREATE SEQUENCE vulnerability_finding_evidence_requests_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE vulnerability_finding_evidence_requests_id_seq OWNED BY vulnerability_finding_evidence_requests.id;
CREATE TABLE vulnerability_finding_evidences (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
......@@ -19845,6 +19865,8 @@ ALTER TABLE ONLY vulnerability_external_issue_links ALTER COLUMN id SET DEFAULT
ALTER TABLE ONLY vulnerability_feedback ALTER COLUMN id SET DEFAULT nextval('vulnerability_feedback_id_seq'::regclass);
ALTER TABLE ONLY vulnerability_finding_evidence_requests ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_evidence_requests_id_seq'::regclass);
ALTER TABLE ONLY vulnerability_finding_evidences ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_evidences_id_seq'::regclass);
ALTER TABLE ONLY vulnerability_finding_links ALTER COLUMN id SET DEFAULT nextval('vulnerability_finding_links_id_seq'::regclass);
......@@ -21475,6 +21497,9 @@ ALTER TABLE ONLY vulnerability_external_issue_links
ALTER TABLE ONLY vulnerability_feedback
ADD CONSTRAINT vulnerability_feedback_pkey PRIMARY KEY (id);
ALTER TABLE ONLY vulnerability_finding_evidence_requests
ADD CONSTRAINT vulnerability_finding_evidence_requests_pkey PRIMARY KEY (id);
ALTER TABLE ONLY vulnerability_finding_evidences
ADD CONSTRAINT vulnerability_finding_evidences_pkey PRIMARY KEY (id);
......@@ -21711,6 +21736,8 @@ CREATE UNIQUE INDEX epic_user_mentions_on_epic_id_index ON epic_user_mentions US
CREATE INDEX expired_artifacts_temp_index ON ci_job_artifacts USING btree (id, created_at) WHERE ((expire_at IS NULL) AND (date(timezone('UTC'::text, created_at)) < '2020-06-22'::date));
CREATE INDEX finding_evidence_requests_on_finding_evidence_id ON vulnerability_finding_evidence_requests USING btree (vulnerability_finding_evidences_id);
CREATE INDEX finding_evidences_on_vulnerability_occurrence_id ON vulnerability_finding_evidences USING btree (vulnerability_occurrence_id);
CREATE INDEX finding_links_on_vulnerability_occurrence_id ON vulnerability_finding_links USING btree (vulnerability_occurrence_id);
......@@ -25825,6 +25852,9 @@ ALTER TABLE ONLY lfs_file_locks
ALTER TABLE ONLY dast_site_profile_secret_variables
ADD CONSTRAINT fk_rails_43e2897950 FOREIGN KEY (dast_site_profile_id) REFERENCES dast_site_profiles(id) ON DELETE CASCADE;
ALTER TABLE ONLY vulnerability_finding_evidence_requests
ADD CONSTRAINT fk_rails_4410592084 FOREIGN KEY (vulnerability_finding_evidences_id) REFERENCES vulnerability_finding_evidences(id) ON DELETE CASCADE;
ALTER TABLE ONLY merge_request_assignees
ADD CONSTRAINT fk_rails_443443ce6f FOREIGN KEY (merge_request_id) REFERENCES merge_requests(id) ON DELETE CASCADE;
......@@ -5,5 +5,7 @@ module Vulnerabilities
self.table_name = 'vulnerability_finding_evidences'
belongs_to :finding, class_name: 'Vulnerabilities::Finding', inverse_of: :finding_evidences, foreign_key: 'vulnerability_occurrence_id', optional: false
has_many :requests, class_name: 'Vulnerabilities::FindingEvidenceRequest', inverse_of: :finding_evidence, foreign_key: 'vulnerability_finding_evidences_id'
end
end
# frozen_string_literal: true
module Vulnerabilities
class FindingEvidenceRequest < ApplicationRecord
self.table_name = 'vulnerability_finding_evidence_requests'
belongs_to :finding_evidence, class_name: 'Vulnerabilities::FindingEvidence', inverse_of: :requests, foreign_key: 'vulnerability_finding_evidences_id', optional: false
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Vulnerabilities::FindingEvidenceRequest do
it { is_expected.to belong_to(:finding_evidence).class_name('Vulnerabilities::FindingEvidence').required }
end
......@@ -4,4 +4,5 @@ require 'spec_helper'
RSpec.describe Vulnerabilities::FindingEvidence do
it { is_expected.to belong_to(:finding).class_name('Vulnerabilities::Finding').required }
it { is_expected.to have_many(:requests).class_name('Vulnerabilities::FindingEvidenceRequest').with_foreign_key('vulnerability_finding_evidences_id') }
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