Commit 6f027eb8 authored by Aditya Tiwari's avatar Aditya Tiwari Committed by Mayra Cabrera

Add Corpus model

parent 86775529
# frozen_string_literal: true
class CreateCoverageFuzzingCorpuses < Gitlab::Database::Migration[1.0]
def change
create_table :coverage_fuzzing_corpuses do |t|
t.bigint :project_id, null: false
t.bigint :user_id
t.bigint :package_id, null: false
t.datetime_with_timezone :file_updated_at, null: false, default: -> { 'NOW()' }
t.timestamps_with_timezone null: false
t.index :project_id
t.index :user_id
t.index :package_id
end
end
end
# frozen_string_literal: true
class AddForeignKeyToCorpusesOnProject < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
add_concurrent_foreign_key :coverage_fuzzing_corpuses, :projects, column: :project_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :coverage_fuzzing_corpuses, column: :project_id
end
end
end
# frozen_string_literal: true
class AddForeignKeyToCorpusesOnUser < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
add_concurrent_foreign_key :coverage_fuzzing_corpuses, :users, column: :user_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :coverage_fuzzing_corpuses, column: :user_id
end
end
end
# frozen_string_literal: true
class AddForeignKeyToCorpusesOnPackage < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
add_concurrent_foreign_key :coverage_fuzzing_corpuses, :packages_packages, column: :package_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :coverage_fuzzing_corpuses, column: :package_id
end
end
end
95dcfdc6c03705b0db5e96d669051edf335b5d6501243f70588f9b73478116a6
\ No newline at end of file
e45163c2d0d691fb5deab86d024c4edb8e3cd350271418e1ff132c31e2ca90a3
\ No newline at end of file
20d35e9baae343bccbb67a25eacd7fdb4b32fd4cedd95e6f8f7a2933470350fb
\ No newline at end of file
4659ab6d971b03d9b44dda72fe1b571c5050fd6892cb4f16f2ca1ced0905c1ce
\ No newline at end of file
......@@ -12724,6 +12724,25 @@ CREATE SEQUENCE conversational_development_index_metrics_id_seq
ALTER SEQUENCE conversational_development_index_metrics_id_seq OWNED BY conversational_development_index_metrics.id;
CREATE TABLE coverage_fuzzing_corpuses (
id bigint NOT NULL,
project_id bigint NOT NULL,
user_id bigint,
package_id bigint NOT NULL,
file_updated_at timestamp with time zone DEFAULT now() NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
CREATE SEQUENCE coverage_fuzzing_corpuses_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE coverage_fuzzing_corpuses_id_seq OWNED BY coverage_fuzzing_corpuses.id;
CREATE TABLE csv_issue_imports (
id bigint NOT NULL,
project_id bigint NOT NULL,
......@@ -21143,6 +21162,8 @@ ALTER TABLE ONLY container_repositories ALTER COLUMN id SET DEFAULT nextval('con
ALTER TABLE ONLY conversational_development_index_metrics ALTER COLUMN id SET DEFAULT nextval('conversational_development_index_metrics_id_seq'::regclass);
ALTER TABLE ONLY coverage_fuzzing_corpuses ALTER COLUMN id SET DEFAULT nextval('coverage_fuzzing_corpuses_id_seq'::regclass);
ALTER TABLE ONLY csv_issue_imports ALTER COLUMN id SET DEFAULT nextval('csv_issue_imports_id_seq'::regclass);
ALTER TABLE ONLY custom_emoji ALTER COLUMN id SET DEFAULT nextval('custom_emoji_id_seq'::regclass);
......@@ -22648,6 +22669,9 @@ ALTER TABLE ONLY container_repositories
ALTER TABLE ONLY conversational_development_index_metrics
ADD CONSTRAINT conversational_development_index_metrics_pkey PRIMARY KEY (id);
ALTER TABLE ONLY coverage_fuzzing_corpuses
ADD CONSTRAINT coverage_fuzzing_corpuses_pkey PRIMARY KEY (id);
ALTER TABLE ONLY csv_issue_imports
ADD CONSTRAINT csv_issue_imports_pkey PRIMARY KEY (id);
......@@ -24803,6 +24827,12 @@ CREATE UNIQUE INDEX index_container_repositories_on_project_id_and_name ON conta
CREATE INDEX index_container_repository_on_name_trigram ON container_repositories USING gin (name gin_trgm_ops);
CREATE INDEX index_coverage_fuzzing_corpuses_on_package_id ON coverage_fuzzing_corpuses USING btree (package_id);
CREATE INDEX index_coverage_fuzzing_corpuses_on_project_id ON coverage_fuzzing_corpuses USING btree (project_id);
CREATE INDEX index_coverage_fuzzing_corpuses_on_user_id ON coverage_fuzzing_corpuses USING btree (user_id);
CREATE INDEX index_created_at_on_codeowner_approval_merge_request_rules ON approval_merge_request_rules USING btree (created_at) WHERE ((rule_type = 2) AND (section <> 'codeowners'::text));
CREATE INDEX index_csv_issue_imports_on_project_id ON csv_issue_imports USING btree (project_id);
......@@ -27496,6 +27526,9 @@ ALTER TABLE ONLY boards
ALTER TABLE ONLY epics
ADD CONSTRAINT fk_1fbed67632 FOREIGN KEY (start_date_sourcing_milestone_id) REFERENCES milestones(id) ON DELETE SET NULL;
ALTER TABLE ONLY coverage_fuzzing_corpuses
ADD CONSTRAINT fk_204d40056a FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY geo_container_repository_updated_events
ADD CONSTRAINT fk_212c89c706 FOREIGN KEY (container_repository_id) REFERENCES container_repositories(id) ON DELETE CASCADE;
......@@ -27535,6 +27568,9 @@ ALTER TABLE ONLY geo_event_log
ALTER TABLE ONLY deployments
ADD CONSTRAINT fk_289bba3222 FOREIGN KEY (cluster_id) REFERENCES clusters(id) ON DELETE SET NULL;
ALTER TABLE ONLY coverage_fuzzing_corpuses
ADD CONSTRAINT fk_29f6f15f82 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY agent_group_authorizations
ADD CONSTRAINT fk_2c9f941965 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
......@@ -28177,6 +28213,9 @@ ALTER TABLE ONLY application_settings
ALTER TABLE ONLY events
ADD CONSTRAINT fk_edfd187b6f FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY coverage_fuzzing_corpuses
ADD CONSTRAINT fk_ef5ebf339f FOREIGN KEY (package_id) REFERENCES packages_packages(id) ON DELETE CASCADE;
ALTER TABLE ONLY vulnerabilities
ADD CONSTRAINT fk_efb96ab1e2 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
# frozen_string_literal: true
module AppSec
module Fuzzing
module Coverage
class Corpus < ApplicationRecord
self.table_name = 'coverage_fuzzing_corpuses'
belongs_to :package, class_name: 'Packages::Package'
belongs_to :user, optional: true
belongs_to :project
end
end
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :corpus, class: 'AppSec::Fuzzing::Coverage::Corpus' do
user
package
project
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AppSec::Fuzzing::Coverage::Corpus, type: :model do
let(:corpus) { create(:corpus) }
subject { corpus }
describe 'associations' do
it { is_expected.to belong_to(:package).class_name('Packages::Package') }
it { is_expected.to belong_to(:user).optional }
it { is_expected.to belong_to(:project) }
end
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