Commit 43177df6 authored by Sean Arnold's avatar Sean Arnold

Use statuses previously defined, improve message

- Remove unused index
parent 3ab56073
...@@ -20,7 +20,6 @@ module AlertManagement ...@@ -20,7 +20,6 @@ module AlertManagement
resolved: 2, resolved: 2,
ignored: 3 ignored: 3
}.freeze }.freeze
private_constant :STATUSES
STATUS_DESCRIPTIONS = { STATUS_DESCRIPTIONS = {
triggered: 'Investigation has not started', triggered: 'Investigation has not started',
......
...@@ -5,12 +5,11 @@ class AddEscalationPolicies < ActiveRecord::Migration[6.0] ...@@ -5,12 +5,11 @@ class AddEscalationPolicies < ActiveRecord::Migration[6.0]
disable_ddl_transaction! disable_ddl_transaction!
POLICY_PROJECT_INDEX_NAME = 'index_on_project_escalation_policy'
UNIQUE_INDEX_NAME = 'index_on_project_id_escalation_policy_name_unique' UNIQUE_INDEX_NAME = 'index_on_project_id_escalation_policy_name_unique'
def up def up
create_table_with_constraints :incident_management_escalation_policies do |t| create_table_with_constraints :incident_management_escalation_policies do |t|
t.references :project, index: { name: POLICY_PROJECT_INDEX_NAME }, null: false, foreign_key: { on_delete: :cascade } t.references :project, index: false, null: false, foreign_key: { on_delete: :cascade }
t.text :name, null: false t.text :name, null: false
t.text :description, null: true t.text :description, null: true
......
...@@ -23614,8 +23614,6 @@ CREATE INDEX index_on_pages_metadata_not_migrated ON project_pages_metadata USIN ...@@ -23614,8 +23614,6 @@ CREATE INDEX index_on_pages_metadata_not_migrated ON project_pages_metadata USIN
CREATE UNIQUE INDEX index_on_policy_schedule_status_elapsed_time_escalation_rules ON incident_management_escalation_rules USING btree (policy_id, oncall_schedule_id, status, elapsed_time); CREATE UNIQUE INDEX index_on_policy_schedule_status_elapsed_time_escalation_rules ON incident_management_escalation_rules USING btree (policy_id, oncall_schedule_id, status, elapsed_time);
CREATE INDEX index_on_project_escalation_policy ON incident_management_escalation_policies USING btree (project_id);
CREATE INDEX index_on_project_escalation_rule ON incident_management_escalation_rules USING btree (policy_id); CREATE INDEX index_on_project_escalation_rule ON incident_management_escalation_rules USING btree (policy_id);
CREATE UNIQUE INDEX index_on_project_id_escalation_policy_name_unique ON incident_management_escalation_policies USING btree (project_id, name); CREATE UNIQUE INDEX index_on_project_id_escalation_policy_name_unique ON incident_management_escalation_policies USING btree (project_id, name);
...@@ -7,13 +7,13 @@ module IncidentManagement ...@@ -7,13 +7,13 @@ module IncidentManagement
belongs_to :policy, class_name: 'EscalationPolicy', inverse_of: 'rules', foreign_key: 'policy_id' belongs_to :policy, class_name: 'EscalationPolicy', inverse_of: 'rules', foreign_key: 'policy_id'
belongs_to :oncall_schedule, class_name: 'OncallSchedule', inverse_of: 'rotations', foreign_key: 'oncall_schedule_id' belongs_to :oncall_schedule, class_name: 'OncallSchedule', inverse_of: 'rotations', foreign_key: 'oncall_schedule_id'
enum status: { acknowledged: 1, resolved: 2 } enum status: AlertManagement::Alert::STATUSES.slice(:acknowledged, :resolved)
validates :status, presence: true validates :status, presence: true
validates :elapsed_time, validates :elapsed_time,
presence: true, presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 24.hours } numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 24.hours }
validates :policy_id, uniqueness: { scope: [:oncall_schedule_id, :status, :elapsed_time] } validates :policy_id, uniqueness: { scope: [:oncall_schedule_id, :status, :elapsed_time], message: _('Must have a unique policy, status, and elapsed time') }
end end
end end
...@@ -7,6 +7,8 @@ RSpec.describe IncidentManagement::EscalationPolicy do ...@@ -7,6 +7,8 @@ RSpec.describe IncidentManagement::EscalationPolicy do
subject { build(:incident_management_escalation_policy) } subject { build(:incident_management_escalation_policy) }
it { is_expected.to be_valid }
describe 'associations' do describe 'associations' do
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
it { is_expected.to have_many(:rules) } it { is_expected.to have_many(:rules) }
...@@ -14,6 +16,7 @@ RSpec.describe IncidentManagement::EscalationPolicy do ...@@ -14,6 +16,7 @@ RSpec.describe IncidentManagement::EscalationPolicy do
describe 'validations' do describe 'validations' do
it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_presence_of(:rules) }
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) } it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) }
it { is_expected.to validate_length_of(:name).is_at_most(72) } it { is_expected.to validate_length_of(:name).is_at_most(72) }
it { is_expected.to validate_length_of(:description).is_at_most(160) } it { is_expected.to validate_length_of(:description).is_at_most(160) }
......
...@@ -8,6 +8,8 @@ RSpec.describe IncidentManagement::EscalationRule do ...@@ -8,6 +8,8 @@ RSpec.describe IncidentManagement::EscalationRule do
subject { build(:incident_management_escalation_rule, policy: policy) } subject { build(:incident_management_escalation_rule, policy: policy) }
it { is_expected.to be_valid }
describe 'associations' do describe 'associations' do
it { is_expected.to belong_to(:policy) } it { is_expected.to belong_to(:policy) }
it { is_expected.to belong_to(:oncall_schedule) } it { is_expected.to belong_to(:oncall_schedule) }
...@@ -17,6 +19,6 @@ RSpec.describe IncidentManagement::EscalationRule do ...@@ -17,6 +19,6 @@ RSpec.describe IncidentManagement::EscalationRule do
it { is_expected.to validate_presence_of(:status) } it { is_expected.to validate_presence_of(:status) }
it { is_expected.to validate_presence_of(:elapsed_time) } it { is_expected.to validate_presence_of(:elapsed_time) }
it { is_expected.to validate_numericality_of(:elapsed_time).is_greater_than_or_equal_to(1).is_less_than_or_equal_to(24.hours) } it { is_expected.to validate_numericality_of(:elapsed_time).is_greater_than_or_equal_to(1).is_less_than_or_equal_to(24.hours) }
it { is_expected.to validate_uniqueness_of(:policy_id).scoped_to([:oncall_schedule_id, :status, :elapsed_time] ) } it { is_expected.to validate_uniqueness_of(:policy_id).scoped_to([:oncall_schedule_id, :status, :elapsed_time] ).with_message('Must have a unique policy, status, and elapsed time') }
end end
end end
...@@ -21308,6 +21308,9 @@ msgstr "" ...@@ -21308,6 +21308,9 @@ msgstr ""
msgid "Multiple uploaders found: %{uploader_types}" msgid "Multiple uploaders found: %{uploader_types}"
msgstr "" msgstr ""
msgid "Must have a unique policy, status, and elapsed time"
msgstr ""
msgid "Must match with the %{codeStart}external_url%{codeEnd} in %{codeStart}/etc/gitlab/gitlab.rb%{codeEnd}." msgid "Must match with the %{codeStart}external_url%{codeEnd} in %{codeStart}/etc/gitlab/gitlab.rb%{codeEnd}."
msgstr "" msgstr ""
......
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