Commit 6dc3874c authored by Tiger Watson's avatar Tiger Watson

Merge branch '222954-add-issue-type-to-issues' into 'master'

Add issue_type to Issues

Closes #222954

See merge request gitlab-org/gitlab!37402
parents c76fbee3 42fc2eaa
......@@ -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]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
# Set default to issue type
add_column :issues, :issue_type, :integer, limit: 2, default: 0, null: false
end
end
def down
with_lock_retries do
remove_column :issues, :issue_type
end
end
end
# frozen_string_literal: true
class AddIssueTypeIndexToIssues < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
INCIDENT_TYPE = 1
INDEX_NAME = 'index_issues_on_incident_issue_type'
def up
add_concurrent_index :issues,
:issue_type, where: "issue_type = #{INCIDENT_TYPE}",
name: INDEX_NAME
end
def down
remove_concurrent_index :issues, :issue_type
end
end
9d30ae6ea32db6cbc5871e214a9c2bf8f1a37fbb586f5e39f6bc2ab58768607b
\ No newline at end of file
13731676720dd93887dc55374c9052f1087a2e817eb347fd63a19d9398899d75
\ No newline at end of file
......@@ -12527,6 +12527,7 @@ CREATE TABLE public.issues (
health_status smallint,
external_key character varying(255),
sprint_id bigint,
issue_type smallint DEFAULT 0 NOT NULL,
CONSTRAINT check_fba63f706d CHECK ((lock_version IS NOT NULL))
);
......@@ -19696,6 +19697,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_incident_issue_type ON public.issues USING btree (issue_type) WHERE (issue_type = 1);
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
......@@ -32,6 +32,7 @@ Issue:
- discussion_locked
- health_status
- external_key
- issue_type
Event:
- id
- target_type
......
......@@ -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
......
......@@ -24,7 +24,8 @@ RSpec.describe Gitlab::JiraImport::ImportIssueWorker do
build(:issue, project_id: project.id, title: 'jira issue')
.as_json.merge(
'label_ids' => [jira_issue_label_1.id, jira_issue_label_2.id], 'assignee_ids' => assignee_ids
).compact
).except('issue_type')
.compact
end
context 'when any exception raised while inserting to DB' 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