Commit cb6244c1 authored by Andreas Brandl's avatar Andreas Brandl

Merge branch '238562-create-issuable_severities-table' into 'master'

Create `IssuableSeverity` model to store a severity level for Incidents

Closes #238562

See merge request gitlab-org/gitlab!40272
parents b70d1130 a0584366
# frozen_string_literal: true
class IssuableSeverity < ApplicationRecord
belongs_to :issue
validates :issue, presence: true, uniqueness: true
validates :severity, presence: true
enum severity: {
unknown: 0,
low: 1,
medium: 2,
high: 3,
critical: 4
}
end
---
title: Add IssuableSeverity to store Incident severity level
merge_request: 40272
author:
type: added
# frozen_string_literal: true
class CreateIssuableSeverities < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
create_table :issuable_severities do |t|
t.references :issue, index: { unique: true }, null: false, foreign_key: { on_delete: :cascade }
t.integer :severity, null: false, default: 0, limit: 2 # 0 - will stand for unknown
end
end
end
def down
with_lock_retries do
drop_table :issuable_severities
end
end
end
b8fcbdab769758753efae992e64bed7f79149c74f08294035a48a03c59bb1c5d
\ No newline at end of file
......@@ -12481,6 +12481,21 @@ CREATE SEQUENCE public.ip_restrictions_id_seq
ALTER SEQUENCE public.ip_restrictions_id_seq OWNED BY public.ip_restrictions.id;
CREATE TABLE public.issuable_severities (
id bigint NOT NULL,
issue_id bigint NOT NULL,
severity smallint DEFAULT 0 NOT NULL
);
CREATE SEQUENCE public.issuable_severities_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.issuable_severities_id_seq OWNED BY public.issuable_severities.id;
CREATE TABLE public.issue_assignees (
user_id integer NOT NULL,
issue_id integer NOT NULL
......@@ -17054,6 +17069,8 @@ ALTER TABLE ONLY public.internal_ids ALTER COLUMN id SET DEFAULT nextval('public
ALTER TABLE ONLY public.ip_restrictions ALTER COLUMN id SET DEFAULT nextval('public.ip_restrictions_id_seq'::regclass);
ALTER TABLE ONLY public.issuable_severities ALTER COLUMN id SET DEFAULT nextval('public.issuable_severities_id_seq'::regclass);
ALTER TABLE ONLY public.issue_links ALTER COLUMN id SET DEFAULT nextval('public.issue_links_id_seq'::regclass);
ALTER TABLE ONLY public.issue_metrics ALTER COLUMN id SET DEFAULT nextval('public.issue_metrics_id_seq'::regclass);
......@@ -18134,6 +18151,9 @@ ALTER TABLE ONLY public.internal_ids
ALTER TABLE ONLY public.ip_restrictions
ADD CONSTRAINT ip_restrictions_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.issuable_severities
ADD CONSTRAINT issuable_severities_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.issue_links
ADD CONSTRAINT issue_links_pkey PRIMARY KEY (id);
......@@ -19855,6 +19875,8 @@ CREATE UNIQUE INDEX index_internal_ids_on_usage_and_project_id ON public.interna
CREATE INDEX index_ip_restrictions_on_group_id ON public.ip_restrictions USING btree (group_id);
CREATE UNIQUE INDEX index_issuable_severities_on_issue_id ON public.issuable_severities USING btree (issue_id);
CREATE UNIQUE INDEX index_issue_assignees_on_issue_id_and_user_id ON public.issue_assignees USING btree (issue_id, user_id);
CREATE INDEX index_issue_assignees_on_user_id ON public.issue_assignees USING btree (user_id);
......@@ -22192,6 +22214,9 @@ ALTER TABLE ONLY public.protected_branch_unprotect_access_levels
ALTER TABLE ONLY public.ci_freeze_periods
ADD CONSTRAINT fk_rails_2e02bbd1a6 FOREIGN KEY (project_id) REFERENCES public.projects(id);
ALTER TABLE ONLY public.issuable_severities
ADD CONSTRAINT fk_rails_2fbb74ad6d FOREIGN KEY (issue_id) REFERENCES public.issues(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.saml_providers
ADD CONSTRAINT fk_rails_306d459be7 FOREIGN KEY (group_id) REFERENCES public.namespaces(id) ON DELETE CASCADE;
......
# frozen_string_literal: true
FactoryBot.define do
factory :issuable_severity do
association :issue, factory: :incident
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe IssuableSeverity, type: :model do
let_it_be(:issuable_severity) { create(:issuable_severity) }
describe 'associations' do
it { is_expected.to belong_to(:issue) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:severity) }
it { is_expected.to validate_presence_of(:issue) }
it { is_expected.to validate_uniqueness_of(:issue) }
end
describe 'enums' do
let(:severity_values) do
{ unknown: 0, low: 1, medium: 2, high: 3, critical: 4 }
end
it { is_expected.to define_enum_for(:severity).with_values(severity_values) }
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