-
Task
-
Resolution: Unresolved
-
Normal
-
None
-
None
-
None
-
Product / Portfolio Work
-
False
-
-
False
-
None
-
Unset
-
None
-
-
Since Incident Owner is a required field, the reminder is no longer needed. This task also include the creation of restriction of IncidentOwner required in database. The Incident Owner reminder should be removed and the tests related as well
IncidentOwner DB restriction:
func addIncidentOwnerRequired() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "202507141300",
Migrate: func(tx *gorm.DB) error {
// Create the function
if err := tx.Exec(`
CREATE OR REPLACE FUNCTION check_incident_owner()
RETURNS TRIGGER AS $$
DECLARE
owner_count integer;
BEGIN
SELECT COUNT(*) INTO owner_count
FROM incident_participants
WHERE incident_id = COALESCE(NEW.incident_id, OLD.incident_id)
AND role = 'incident_owner'; IF owner_count <> 1 THEN
RAISE EXCEPTION 'Incident % must have exactly one incident_owner', COALESCE(NEW.incident_id, OLD.incident_id);
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
`).Error; err != nil {
return err
} // Create the trigger
if err := tx.Exec(`
CREATE TRIGGER incident_owner_check
AFTER INSERT OR UPDATE OR DELETE ON incident_participants
FOR EACH ROW
EXECUTE FUNCTION check_incident_owner();
`).Error; err != nil {
return err
} return nil
},
Rollback: func(tx *gorm.DB) error {
// Drop the trigger
if err := tx.Exec(`DROP TRIGGER IF EXISTS incident_owner_check ON incident_participants;`).Error; err != nil {
return err
}
// Drop the function
if err := tx.Exec(`DROP FUNCTION IF EXISTS check_incident_owner();`).Error; err != nil {
return err
}
return nil
},
}
}