Outages
Developer Guide
1. Introduction
This document provides a detailed technical specification for building the Outage Dashboard and its associated management screens. The core design principle is a seamless user experience where the system intelligently handles the distinction between standalone, master, and child outages based on user actions, rather than requiring explicit choices.
2. Core Data Model & Required Schema
The entire feature is powered by two primary tables: outage and outage_update.
- outage: The single source of truth for all outage records.
- outage_update: The chronological log for each outage's timeline.
It is assumed the outage table includes an affected_location_ids UUID[] column to support location-specific outages.
3. Part 1: Main Outage Dashboard Screen (/outages)
Data Fetching & Display Logic
The main table provides a high-level summary and must only display master and standalone outages. Child outages are intentionally hidden from this view to reduce clutter.
Primary SQL Query:
Row Rendering Logic (Client-Side)
For each row returned by the query:
- If is_master is true:
- Affected Client(s): Display the child_count value (e.g., "3 clients"). This should be a link that, when clicked, shows a popover with the names of the affected clients.
- Affected Locations: Display a static summary string like "Multiple".
- Linked Ticket: Display a hyphen (-).
- If is_master is false:
- Affected Client(s): Display the organization_name from the query.
- Affected Locations: Fetch the names of the locations from the location table using the IDs in the affected_location_ids array and display them as a comma-separated list.
- Linked Ticket: Display the ticket_number.
4. Part 2: View/Manage Outage Screen (/outages/{id})
This screen is the central command center for a specific outage. The content is determined by whether the loaded outage (id) is a master or a standalone record.
Data Fetching
On page load, fetch the primary outage record by its id. Then, perform subsequent queries to populate the different sections.
Component Breakdown & Logic
- Header: Displays title, status, vendor.name, and a dynamically calculated Duration from the primary outage record.
- Details Section: Displays editable fields from the primary outage record. An UPDATE query is triggered on the outage table when a field is saved.
- Affected Organizations Section:
- If Master Outage: This section is populated by SELECT o.id, org.name, o.affected_location_ids FROM outage o JOIN organization org ON o.organization_id = org.id WHERE o.parent_outage_id = ?.
- If Standalone Outage: This section lists the single client from the primary outage record's organization_id.
- Timeline Section:
- If Master Outage: The timeline must be comprehensive. The query should be: SELECT * FROM outage_update WHERE outage_id = ? OR outage_id IN (SELECT id FROM outage WHERE parent_outage_id = ?) ORDER BY posted_at_utc DESC. This combines updates from the master and all its children.
- If Standalone Outage: The query is simpler: SELECT * FROM outage_update WHERE outage_id = ? ORDER BY posted_at_utc DESC.
- Related Tickets Section:
- If Master Outage: The query is: SELECT t.ticket_number, org.name FROM outage o JOIN ticket t ON o.related_ticket_id = t.id JOIN organization org ON o.organization_id = org.id WHERE o.parent_outage_id = ?.
- If Standalone Outage: Displays the single ticket from the primary outage record's related_ticket_id.
5. Part 3: Detailed Modal & Workflow Logic
"Add Outage" Modal (from main dashboard)
- UI Logic: The "Affected Location(s)" dropdown is dynamically populated based on the organization(s) selected. If multiple organizations are selected, the location dropdown is disabled and shows "All locations will be affected".
- Backend Logic on "Add Outage" button click:
- If 1 organization is selected:
- INSERT a single record into the outage table.
- Set is_master = false, parent_outage_id = NULL.
- Save the selected organization_id and the array of affected_location_ids.
- If "Create and link a new ticket" is toggled, create a ticket and UPDATE this new outage record with the ticket.id.
- If >1 organization is selected:
- INSERT one master record into outage. Set is_master = true and organization_id to the MSP's own ID.
- Loop through the selected organizations and INSERT multiple child records, setting parent_outage_id to the new master ID. affected_location_ids can be set to all locations for each client.
- If "Create and link a new ticket" is toggled, create a ticket for each child outage and UPDATE each child record with its respective ticket.id.
"Add Organization" Modal (from View Screen)
- Pre-condition: This workflow is only available when viewing a master outage.
- Backend Logic on "Add" button click:
- INSERT a new child outage record.
- Set its parent_outage_id to the ID of the master outage being viewed.
- If the ticket toggle is on, create a linked ticket for this new child outage.
"Add update" Modal (from View Screen)
- Backend Logic on "Add update" button click:
- INSERT a new record into outage_update.
- outage_id is the ID of the outage being viewed (the master record).
- event_type is 'Note'.
"Resolve Outage" Wizard Modal
- Backend Logic on "Confirm and resolve" button click:
- Start Transaction.
- Gather IDs: Get the ID of the master outage and all of its child outage IDs.
- Update Outages: UPDATE outage SET status = 'Resolved', end_time_utc = ? WHERE id IN (...) using the collected IDs and the end time from Step 1.
- Post Final Updates:
- INSERT into outage_update for the master outage, using the Resolution Summary from Step 1.
- INSERT into outage_update for the master outage, using the Update Message from Step 3.
- Problem Management: Loop through the choices from Step 2. For each organization:
- If "New Record", INSERT into problem and then INSERT into problem_incident_link.
- If "Existing Record", find the problem_id and INSERT into problem_incident_link.
- Send Notifications: If the "Send notification" toggle was on in Step 3, generate and send a notice linked to the master outage (target_entity_type = 'outage', target_entity_id = master_outage_id).
- Commit Transaction.