Commit a2a88b30 authored by Sean Arnold's avatar Sean Arnold

Rename elapsed_time to elapsed_time_seconds

parent 2b6024b5
......@@ -12,9 +12,9 @@ class AddEscalationRules < ActiveRecord::Migration[6.0]
t.belongs_to :policy, index: { name: RULE_POLICY_INDEX_NAME }, null: false, foreign_key: { on_delete: :cascade, to_table: :incident_management_escalation_policies }
t.belongs_to :oncall_schedule, index: { name: RULE_SCHEDULE_INDEX_NAME }, null: false, foreign_key: { on_delete: :cascade, to_table: :incident_management_oncall_schedules }
t.integer :status, null: false, limit: 2
t.integer :elapsed_time, null: false, limit: 4
t.integer :elapsed_time_seconds, null: false, limit: 4
t.index [:policy_id, :oncall_schedule_id, :status, :elapsed_time], unique: true, name: UNIQUENESS_INDEX_NAME
t.index [:policy_id, :oncall_schedule_id, :status, :elapsed_time_seconds], unique: true, name: UNIQUENESS_INDEX_NAME
end
end
end
......@@ -13646,7 +13646,7 @@ CREATE TABLE incident_management_escalation_rules (
policy_id bigint NOT NULL,
oncall_schedule_id bigint NOT NULL,
status smallint NOT NULL,
elapsed_time integer NOT NULL
elapsed_time_seconds integer NOT NULL
);
CREATE SEQUENCE incident_management_escalation_rules_id_seq
......@@ -23612,7 +23612,7 @@ CREATE INDEX index_on_oncall_schedule_escalation_rule ON incident_management_esc
CREATE INDEX index_on_pages_metadata_not_migrated ON project_pages_metadata USING btree (project_id) WHERE ((deployed = true) AND (pages_deployment_id IS NULL));
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_seconds);
CREATE INDEX index_on_project_escalation_rule ON incident_management_escalation_rules USING btree (policy_id);
......@@ -10,10 +10,10 @@ module IncidentManagement
enum status: AlertManagement::Alert::STATUSES.slice(:acknowledged, :resolved)
validates :status, presence: true
validates :elapsed_time,
validates :elapsed_time_seconds,
presence: true,
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], message: _('Must have a unique policy, status, and elapsed time') }
validates :policy_id, uniqueness: { scope: [:oncall_schedule_id, :status, :elapsed_time_seconds], message: _('Must have a unique policy, status, and elapsed time') }
end
end
......@@ -5,6 +5,6 @@ FactoryBot.define do
association :policy, factory: :incident_management_escalation_policy
association :oncall_schedule, factory: :incident_management_oncall_schedule
status { IncidentManagement::EscalationRule.statuses[:acknowledged] }
elapsed_time { 5 }
elapsed_time_seconds { 5.minutes }
end
end
......@@ -17,8 +17,8 @@ RSpec.describe IncidentManagement::EscalationRule do
describe 'validations' do
it { is_expected.to validate_presence_of(:status) }
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_uniqueness_of(:policy_id).scoped_to([:oncall_schedule_id, :status, :elapsed_time] ).with_message('Must have a unique policy, status, and elapsed time') }
it { is_expected.to validate_presence_of(:elapsed_time_seconds) }
it { is_expected.to validate_numericality_of(:elapsed_time_seconds).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_seconds] ).with_message('Must have a unique policy, status, and elapsed time') }
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