Commit fb02ab6a authored by James Fargher's avatar James Fargher

Merge branch 'add_dast_scanner_profile_to_db_229729' into 'master'

Add	dast_scanner_profiles to DB

See merge request gitlab-org/gitlab!37404
parents 807598af 0f66a078
# frozen_string_literal: true
class CreateDastScannerProfile < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
unless table_exists?(:dast_scanner_profiles)
with_lock_retries do
create_table :dast_scanner_profiles do |t|
t.timestamps_with_timezone null: false
t.references :project, null: false, index: false, foreign_key: { on_delete: :cascade }, type: :integer
t.integer :spider_timeout, limit: 2
t.integer :target_timeout, limit: 2
t.text :name, null: false
t.index [:project_id, :name], unique: true
end
end
end
add_text_limit(:dast_scanner_profiles, :name, 255)
end
def down
with_lock_retries do
drop_table :dast_scanner_profiles
end
end
end
53c373e95eb78ddc79eaa07d7638d9e1dbe055838da435fdae1c3d45c6babe0e
\ No newline at end of file
......@@ -11004,6 +11004,26 @@ CREATE SEQUENCE public.custom_emoji_id_seq
ALTER SEQUENCE public.custom_emoji_id_seq OWNED BY public.custom_emoji.id;
CREATE TABLE public.dast_scanner_profiles (
id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
project_id integer NOT NULL,
spider_timeout smallint,
target_timeout smallint,
name text NOT NULL,
CONSTRAINT check_568568fabf CHECK ((char_length(name) <= 255))
);
CREATE SEQUENCE public.dast_scanner_profiles_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.dast_scanner_profiles_id_seq OWNED BY public.dast_scanner_profiles.id;
CREATE TABLE public.dast_site_profiles (
id bigint NOT NULL,
project_id bigint NOT NULL,
......@@ -16762,6 +16782,8 @@ ALTER TABLE ONLY public.conversational_development_index_metrics ALTER COLUMN id
ALTER TABLE ONLY public.custom_emoji ALTER COLUMN id SET DEFAULT nextval('public.custom_emoji_id_seq'::regclass);
ALTER TABLE ONLY public.dast_scanner_profiles ALTER COLUMN id SET DEFAULT nextval('public.dast_scanner_profiles_id_seq'::regclass);
ALTER TABLE ONLY public.dast_site_profiles ALTER COLUMN id SET DEFAULT nextval('public.dast_site_profiles_id_seq'::regclass);
ALTER TABLE ONLY public.dast_sites ALTER COLUMN id SET DEFAULT nextval('public.dast_sites_id_seq'::regclass);
......@@ -17745,6 +17767,9 @@ ALTER TABLE ONLY public.conversational_development_index_metrics
ALTER TABLE ONLY public.custom_emoji
ADD CONSTRAINT custom_emoji_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.dast_scanner_profiles
ADD CONSTRAINT dast_scanner_profiles_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.dast_site_profiles
ADD CONSTRAINT dast_site_profiles_pkey PRIMARY KEY (id);
......@@ -19273,6 +19298,8 @@ CREATE UNIQUE INDEX index_custom_emoji_on_namespace_id_and_name ON public.custom
CREATE UNIQUE INDEX index_daily_build_group_report_results_unique_columns ON public.ci_daily_build_group_report_results USING btree (project_id, ref_path, date, group_name);
CREATE UNIQUE INDEX index_dast_scanner_profiles_on_project_id_and_name ON public.dast_scanner_profiles USING btree (project_id, name);
CREATE INDEX index_dast_site_profiles_on_dast_site_id ON public.dast_site_profiles USING btree (dast_site_id);
CREATE UNIQUE INDEX index_dast_site_profiles_on_project_id_and_name ON public.dast_site_profiles USING btree (project_id, name);
......@@ -22284,6 +22311,9 @@ ALTER TABLE ONLY public.list_user_preferences
ALTER TABLE ONLY public.project_custom_attributes
ADD CONSTRAINT fk_rails_719c3dccc5 FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.dast_scanner_profiles
ADD CONSTRAINT fk_rails_72a8ba7141 FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.vulnerability_historical_statistics
ADD CONSTRAINT fk_rails_72b73ed023 FOREIGN KEY (project_id) REFERENCES public.projects(id) ON DELETE CASCADE;
......
# frozen_string_literal: true
class DastScannerProfile < ApplicationRecord
belongs_to :project
validates :project_id, presence: true
validates :name, length: { maximum: 255 }, uniqueness: { scope: :project_id }
end
# frozen_string_literal: true
FactoryBot.define do
factory :dast_scanner_profile do
name { FFaker::Product.product_name }
before(:create) do |dast_scanner_profile|
dast_scanner_profile.project ||= FactoryBot.create(:project)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe DastScannerProfile, type: :model do
subject { create(:dast_scanner_profile) }
describe 'associations' do
it { is_expected.to belong_to(:project) }
end
describe 'validations' do
it { is_expected.to be_valid }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) }
it { is_expected.to validate_presence_of(:project_id) }
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