---
title: Outages
slug: outages
createdAt: 2025-08-20T00:04:03.997Z
---

# 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:**

:::BlockQuote
SELECT
&#x20;   o.id,
&#x20;   o.title,
&#x20;   o.status,
&#x20;   o.start\_time\_utc,
&#x20;   o.is\_master,
&#x20;   v.name AS vendor\_name,
&#x20;   org.name AS organization\_name,
&#x20;   t.ticket\_number,
&#x20;   (SELECT COUNT(\*) FROM outage child WHERE child.parent\_outage\_id = o.id) AS child\_count
FROM
&#x20;   outage o
LEFT JOIN vendor v ON o.vendor\_id = v.id
LEFT JOIN organization org ON o.organization\_id = org.id
LEFT JOIN ticket t ON o.related\_ticket\_id = t.id
WHERE
&#x20;   o.parent\_outage\_id IS NULL
&#x20;   AND o.status NOT IN ('Resolved', 'Closed')
ORDER BY
&#x20;   o.start\_time\_utc DESC;

:::

**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/&#x7B;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**:
  1. **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.
  2. **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**:
  1. INSERT a new **child** outage record.
  2. Set its parent\_outage\_id to the ID of the master outage being viewed.
  3. 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**:
  1. INSERT a new record into outage\_update.
  2. outage\_id is the ID of the outage being viewed (the master record).
  3. event\_type is 'Note'.

**"Resolve Outage" Wizard Modal**

- **Backend Logic on "Confirm and resolve" button click**:
  1. **Start Transaction**.
  2. **Gather IDs**: Get the ID of the master outage and all of its child outage IDs.
  3. **Update Outages**: UPDATE outage SET status = 'Resolved', end\_time\_utc = ? WHERE id IN (...) using the collected IDs and the end time from Step 1.
  4. **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.
  5. **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.
  6. **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).
  7. **Commit Transaction**.

## Time Tracking

