Commit 4ed23ba8 authored by Sean Arnold's avatar Sean Arnold

Add issue_type to Issues

- Add index
- Enum type
parent 85d00751
......@@ -68,6 +68,12 @@ class Issue < ApplicationRecord
accepts_nested_attributes_for :sentry_issue
validates :project, presence: true
validates :issue_type, presence: true
enum issue_type: {
issue: 0,
incident: 1
}
alias_attribute :parent_ids, :project_id
alias_method :issuing_parent, :project
......
---
title: Add issue_type column to issues table
merge_request: 37402
author:
type: added
# frozen_string_literal: true
class AddIssueTypeToIssues < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
# Set default to issue type
add_column :issues, :issue_type, :integer, limit: 2, default: 0
end
end
# frozen_string_literal: true
class AddIssueTypeIndexToIssues < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :issues, :issue_type
end
def down
remove_concurrent_index :issues, :issue_type
end
end
......@@ -12527,7 +12527,7 @@ CREATE TABLE public.issues (
health_status smallint,
external_key character varying(255),
sprint_id bigint,
CONSTRAINT check_fba63f706d CHECK ((lock_version IS NOT NULL))
issue_type smallint DEFAULT 0
);
CREATE SEQUENCE public.issues_id_seq
......@@ -19696,6 +19696,8 @@ CREATE INDEX index_issues_on_description_trigram ON public.issues USING gin (des
CREATE INDEX index_issues_on_duplicated_to_id ON public.issues USING btree (duplicated_to_id) WHERE (duplicated_to_id IS NOT NULL);
CREATE INDEX index_issues_on_issue_type ON public.issues USING btree (issue_type);
CREATE INDEX index_issues_on_last_edited_by_id ON public.issues USING btree (last_edited_by_id);
CREATE INDEX index_issues_on_milestone_id ON public.issues USING btree (milestone_id);
......
......@@ -7,6 +7,7 @@ FactoryBot.define do
author { project.creator }
updated_by { author }
relative_position { RelativePositioning::START_POSITION }
issue_type { :issue }
trait :confidential do
confidential { true }
......@@ -41,5 +42,9 @@ FactoryBot.define do
issue.update!(labels: evaluator.labels)
end
end
factory :incident do
issue_type { :incident }
end
end
end
......@@ -58,6 +58,26 @@ RSpec.describe Issue do
end
end
describe 'validations' do
subject { issue.valid? }
describe 'issue_type' do
let(:issue) { build(:issue, issue_type: issue_type) }
context 'when a valid type' do
let(:issue_type) { :issue }
it { is_expected.to eq(true) }
end
context 'empty type' do
let(:issue_type) { nil }
it { is_expected.to eq(false) }
end
end
end
subject { create(:issue) }
describe 'callbacks' do
......
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