# Status page database schema

Source: https://personalsoftwarefactory.com/schemas/status-page
Updated: 2026-12-04

> Sixteen tables. The design rests on status_changes, an append-only log of every component status change that uptime and the 90-day bars are computed from, and on incident_updates with a child table of the component statuses each update set, which decides who gets emailed. A component's current status is stored for the page, but R6 defines it as the worst status still set by open incidents and running maintenance. Subscribers follow either all components or a list of them.

- 16 tables, 2 indexes
- Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite 0.6.1) on 2026-12-04
- 49 seed rows from the blueprint
- The blueprint's test build passed 18 of 18 acceptance checks

Files: [status-page.sql](https://personalsoftwarefactory.com/schemas/status-page.sql) · [status-page-seed.sql](https://personalsoftwarefactory.com/schemas/status-page-seed.sql) · [the Status Page blueprint](https://personalsoftwarefactory.com/blueprints/status-page)

## Relationships

- components.group_id references component_groups.id: each components row points to at most one component_groups row, and one component_groups row can have many components rows pointing to it.
- components.template_id references templates.id: each components row points to at most one templates row, and one templates row can have many components rows pointing to it.
- template_components.template_id references templates.id: each template_components row points to exactly one templates row, and one templates row can have many template_components rows pointing to it. On delete: cascade.
- template_components.component_id references components.id: each template_components row points to exactly one components row, and one components row can have many template_components rows pointing to it.
- incidents.created_by references team_members.id: each incidents row points to at most one team_members row, and one team_members row can have many incidents rows pointing to it.
- incidents.related_to references incidents.id: each incidents row points to at most one another incidents row, and one incidents row can have many incidents rows pointing to it.
- incident_updates.incident_id references incidents.id: each incident_updates row points to exactly one incidents row, and one incidents row can have many incident_updates rows pointing to it. On delete: cascade.
- incident_updates.author_id references team_members.id: each incident_updates row points to at most one team_members row, and one team_members row can have many incident_updates rows pointing to it.
- incident_update_components.update_id references incident_updates.id: each incident_update_components row points to exactly one incident_updates row, and one incident_updates row can have many incident_update_components rows pointing to it. On delete: cascade.
- incident_update_components.component_id references components.id: each incident_update_components row points to exactly one components row, and one components row can have many incident_update_components rows pointing to it.
- maintenance_components.maintenance_id references maintenance_windows.id: each maintenance_components row points to exactly one maintenance_windows row, and one maintenance_windows row can have many maintenance_components rows pointing to it. On delete: cascade.
- maintenance_components.component_id references components.id: each maintenance_components row points to exactly one components row, and one components row can have many maintenance_components rows pointing to it.
- status_changes.component_id references components.id: each status_changes row points to exactly one components row, and one components row can have many status_changes rows pointing to it.
- status_changes.incident_id references incidents.id: each status_changes row points to at most one incidents row, and one incidents row can have many status_changes rows pointing to it.
- status_changes.maintenance_id references maintenance_windows.id: each status_changes row points to at most one maintenance_windows row, and one maintenance_windows row can have many status_changes rows pointing to it.
- subscriber_components.subscriber_id references subscribers.id: each subscriber_components row points to exactly one subscribers row, and one subscribers row can have many subscriber_components rows pointing to it. On delete: cascade.
- subscriber_components.component_id references components.id: each subscriber_components row points to exactly one components row, and one components row can have many subscriber_components rows pointing to it.
- notifications.incident_id references incidents.id: each notifications row points to at most one incidents row, and one incidents row can have many notifications rows pointing to it.
- notifications.maintenance_id references maintenance_windows.id: each notifications row points to at most one maintenance_windows row, and one maintenance_windows row can have many notifications rows pointing to it.

## Tables

Also described as: incident status page database design, uptime status page data model, Statuspage alternative database tables.

### settings

The one row with the page name, company name, time zone, sender, sign-in domain and public address. Implements: Settings.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | INTEGER | no |  | Primary key | Check: `id = 1` |
| `page_name` | TEXT | no |  |  |  |
| `company_name` | TEXT | no |  |  | every public update is signed with it |
| `logo` | TEXT | yes |  |  | image URL or file path |
| `time_zone` | TEXT | no | `'America/Chicago'` |  | IANA name; used for days in uptime bars, emails and admin screens |
| `support_url` | TEXT | yes |  |  |  |
| `from_email` | TEXT | yes |  |  |  |
| `email_domain` | TEXT | yes |  |  | the only domain team members sign in with |
| `page_url` | TEXT | yes |  |  | the public address used in every email and feed link |

### team_members

A person on the team who can sign in, as an admin or a responder. Implements: TeamMember.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | never shown to visitors (R11) |
| `email` | TEXT | no |  | Unique |  |
| `role` | TEXT | no |  |  | Check: `role IN ('admin', 'responder')` |
| `active` | BOOLEAN | no | `TRUE` |  | only active members can sign in |

### component_groups

A heading on the public page that components are listed under. Implements: ComponentGroup.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  | Unique |  |
| `position` | INTEGER | no |  |  | display order |

### templates

A saved incident title and first message, used by people and by automation. Implements: Template.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  |  |
| `title` | TEXT | no |  |  | the incident title it fills in |
| `message` | TEXT | no |  |  | the message of the first update |

### components

A part of the product with its current status, automation token and template. Implements: Component.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  | Unique |  |
| `description` | TEXT | yes |  |  | shown on the public page |
| `group_id` | TEXT | yes |  | References component_groups.id | a group with components cannot be deleted |
| `position` | INTEGER | no |  |  | display order within its group |
| `status` | TEXT | no | `'operational'` |  | Check: `status IN ('operational', 'degraded_performance', 'partial_outage', 'major_outage', 'under_maintenance')` |
| `created_at` | TIMESTAMP | no |  |  | uptime counts from here when it is inside the 90-day window |
| `hidden` | BOOLEAN | no | `FALSE` |  | hidden components keep their history and do not count toward the banner |
| `automation_token` | TEXT | yes |  | Unique | secret for the monitor webhook (R10); generated by the app |
| `auto_publish` | BOOLEAN | no | `FALSE` |  | publish automation incidents at once instead of leaving a draft |
| `template_id` | TEXT | yes |  | References templates.id | used by automation; NULL gives the title "Payments: major outage" |

- App rule (R6): status is always the worst of the latest status each open incident set for it and
- App rule (section 13): a component used by any incident, maintenance or template can only be hidden, not deleted.

### template_components

A component a template sets, with the status it sets. Implements: child table of Template.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `template_id` | TEXT | no |  | Primary key (part); References templates.id, on delete cascade |  |
| `component_id` | TEXT | no |  | Primary key (part); References components.id |  |
| `status` | TEXT | no |  |  | Check: `status IN ('operational', 'degraded_performance', 'partial_outage', 'major_outage')` |

### incidents

An incident, from draft to resolved, with its impact, times and postmortem. Implements: Incident.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `number` | INTEGER | no |  | Unique | shown as INC-0013; given when the draft is created Check: `number >= 1` |
| `title` | TEXT | no |  |  |  |
| `status` | TEXT | no | `'draft'` |  | Check: `status IN ('draft', 'investigating', 'identified', 'monitoring', 'resolved')` |
| `impact` | TEXT | no | `'minor'` |  | Check: `impact IN ('none', 'minor', 'major', 'critical')` |
| `started_at` | TIMESTAMP | yes |  |  | set when it is published |
| `resolved_at` | TIMESTAMP | yes |  |  |  |
| `postmortem` | TEXT | yes |  |  | Markdown; resolved incidents only Check: `length(postmortem) <= 20000` |
| `postmortem_at` | TIMESTAMP | yes |  |  | when the postmortem was last added or edited |
| `created_by` | TEXT | yes |  | References team_members.id | NULL when automation opened it |
| `related_to` | TEXT | yes |  | References incidents.id | an earlier incident this one follows on from |

- Table check: `(status = 'draft' AND started_at IS NULL) OR (status <> 'draft' AND started_at IS NOT NULL)`
- Table check: `(status = 'resolved' AND resolved_at IS NOT NULL) OR (status <> 'resolved' AND resolved_at IS NULL)`
- Table check: `postmortem IS NULL OR status = 'resolved'`
- App rule (R4): status moves forward only (investigating, identified, monitoring, resolved); steps can be skipped.
- App rule: only drafts can be deleted, and the number of a deleted draft is not reused.

### incident_updates

One timed update on an incident; a draft's text is its unpublished first update. Implements: IncidentUpdate.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `incident_id` | TEXT | no |  | References incidents.id, on delete cascade | cascade only matters for deleted drafts |
| `status` | TEXT | no |  |  | Check: `status IN ('investigating', 'identified', 'monitoring', 'resolved')` |
| `message` | TEXT | no |  |  | Check: `length(message) BETWEEN 10 AND 2000` |
| `notify` | BOOLEAN | no |  |  | email subscribers of the affected components of the incident (R9) |
| `published_at` | TIMESTAMP | yes |  |  | NULL only for the text of a draft |
| `author_id` | TEXT | yes |  | References team_members.id | NULL for automation; never shown publicly |

- App rule (R5): an admin can correct the message after publishing; the original stays in the activity log.

### incident_update_components

A component status set by one update (the update's component_statuses). Implements: child table of IncidentUpdate.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `update_id` | TEXT | no |  | Primary key (part); References incident_updates.id, on delete cascade |  |
| `component_id` | TEXT | no |  | Primary key (part); References components.id |  |
| `status` | TEXT | no |  |  | Check: `status IN ('operational', 'degraded_performance', 'partial_outage', 'major_outage')` |

### maintenance_windows

A scheduled maintenance window with its start, end, status and notify flag. Implements: Maintenance.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `number` | INTEGER | no |  | Unique | shown as M-0003 Check: `number >= 1` |
| `title` | TEXT | no |  |  |  |
| `message` | TEXT | yes |  |  | optional |
| `starts_at` | TIMESTAMP | no |  |  |  |
| `ends_at` | TIMESTAMP | no |  |  |  |
| `status` | TEXT | no | `'scheduled'` |  | Check: `status IN ('scheduled', 'in_progress', 'completed', 'cancelled')` |
| `notify` | BOOLEAN | no |  |  |  |

- Table check: `ends_at > starts_at`
- App rule (R7): the every-minute job starts and completes it on time and sends a reminder 1 hour before.

### maintenance_components

A component a maintenance window puts under maintenance. Implements: child table of Maintenance.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `maintenance_id` | TEXT | no |  | Primary key (part); References maintenance_windows.id, on delete cascade |  |
| `component_id` | TEXT | no |  | Primary key (part); References components.id |  |

### status_changes

One change of a component's status, with the incident or maintenance and the actor behind it. Implements: StatusChange.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `component_id` | TEXT | no |  | References components.id |  |
| `status` | TEXT | no |  |  | Check: `status IN ('operational', 'degraded_performance', 'partial_outage', 'major_outage', 'under_maintenance')` |
| `at` | TIMESTAMP | no |  |  |  |
| `incident_id` | TEXT | yes |  | References incidents.id |  |
| `maintenance_id` | TEXT | yes |  | References maintenance_windows.id |  |
| `actor` | TEXT | no |  |  | a team member id, 'automation' or 'schedule' |

- Table check: `incident_id IS NULL OR maintenance_id IS NULL`
- Index `status_changes_component_at` on (component_id, at)

### subscribers

An email address subscribed to updates, with its confirmation and unsubscribe state. Implements: Subscriber.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `email` | TEXT | no |  | Unique | stored lowercase Check: `email = lower(email)` |
| `all_components` | BOOLEAN | no | `FALSE` |  | TRUE: every component, and subscriber_components is empty |
| `confirm_token` | TEXT | yes |  | Unique | generated by the app |
| `confirm_sent_at` | TIMESTAMP | yes |  |  |  |
| `confirmed_at` | TIMESTAMP | yes |  |  | only confirmed subscribers are emailed |
| `manage_token` | TEXT | yes |  | Unique | for the manage and one-click unsubscribe links; generated by the app |
| `unsubscribed_at` | TIMESTAMP | yes |  |  |  |
| `created_ip` | TEXT | yes |  |  |  |

- App rule (R8): double opt-in; the confirmation link expires 7 days after confirm_sent_at.

### subscriber_components

A component a subscriber follows when they don't follow all of them. Implements: child table of Subscriber.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `subscriber_id` | TEXT | no |  | Primary key (part); References subscribers.id, on delete cascade |  |
| `component_id` | TEXT | no |  | Primary key (part); References components.id |  |

### events

One entry in the append-only activity log, naming its actor. Implements: Event.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `at` | TIMESTAMP | no |  |  |  |
| `actor` | TEXT | no |  |  | a team member id, 'schedule', 'automation', 'visitor' or 'outbox' |
| `type` | TEXT | no |  |  |  |
| `data` | TEXT | no | `'{}'` |  | a JSON object stored as text |

### notifications

One email in the outbox with its subject, headers, attempts and status. Implements: Notification.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `kind` | TEXT | no |  |  |  |
| `to_email` | TEXT | no |  |  |  |
| `subject` | TEXT | no |  |  |  |
| `body` | TEXT | no |  |  |  |
| `headers` | TEXT | yes |  |  | extra headers such as List-Unsubscribe, as text |
| `created_at` | TIMESTAMP | no |  |  |  |
| `incident_id` | TEXT | yes |  | References incidents.id |  |
| `maintenance_id` | TEXT | yes |  | References maintenance_windows.id |  |
| `attempts` | INTEGER | no | `0` |  | at most 3 send attempts per email Check: `attempts BETWEEN 0 AND 3` |
| `status` | TEXT | no | `'queued'` |  | Check: `status IN ('queued', 'sent', 'failed', 'logged')` |
| `error` | TEXT | yes |  |  |  |

- Table check: `incident_id IS NULL OR maintenance_id IS NULL`
- Index `notifications_status` on (status)

## The SQL

```sql
-- Status Page database schema
-- Source: https://personalsoftwarefactory.com/blueprints/status-page (data model, section 5 of the blueprint)
-- Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite). All timestamps are UTC.
-- License: MIT. Free to copy and adapt.

-- The single settings row. id is fixed at 1 so the table can never hold a second row.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY CHECK (id = 1),
  page_name TEXT NOT NULL,
  company_name TEXT NOT NULL, -- every public update is signed with it
  logo TEXT, -- image URL or file path
  time_zone TEXT NOT NULL DEFAULT 'America/Chicago', -- IANA name; used for days in uptime bars, emails and admin screens
  support_url TEXT,
  from_email TEXT,
  email_domain TEXT, -- the only domain team members sign in with
  page_url TEXT -- the public address used in every email and feed link
);

-- A person on the team who can sign in to /admin.
CREATE TABLE team_members (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL, -- never shown to visitors (R11)
  email TEXT NOT NULL UNIQUE,
  role TEXT NOT NULL CHECK (role IN ('admin', 'responder')),
  active BOOLEAN NOT NULL DEFAULT TRUE -- only active members can sign in
);

-- A heading on the public page that components are listed under. Deleted only when empty.
CREATE TABLE component_groups (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL UNIQUE,
  position INTEGER NOT NULL -- display order
);

-- A saved starting point for an incident: title, first message and component statuses.
CREATE TABLE templates (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  title TEXT NOT NULL, -- the incident title it fills in
  message TEXT NOT NULL -- the message of the first update
);

-- A part of the product shown on the page with its current status.
-- App rule (R6): status is always the worst of the latest status each open incident set for it and
-- under_maintenance for each in-progress maintenance affecting it, or operational.
-- App rule (section 13): a component used by any incident, maintenance or template can only be hidden, not deleted.
CREATE TABLE components (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL UNIQUE,
  description TEXT, -- shown on the public page
  group_id TEXT REFERENCES component_groups(id), -- a group with components cannot be deleted
  position INTEGER NOT NULL, -- display order within its group
  status TEXT NOT NULL DEFAULT 'operational' CHECK (status IN ('operational', 'degraded_performance', 'partial_outage', 'major_outage', 'under_maintenance')),
  created_at TIMESTAMP NOT NULL, -- uptime counts from here when it is inside the 90-day window
  hidden BOOLEAN NOT NULL DEFAULT FALSE, -- hidden components keep their history and do not count toward the banner
  automation_token TEXT UNIQUE, -- secret for the monitor webhook (R10); generated by the app
  auto_publish BOOLEAN NOT NULL DEFAULT FALSE, -- publish automation incidents at once instead of leaving a draft
  template_id TEXT REFERENCES templates(id) -- used by automation; NULL gives the title "Payments: major outage"
);

-- A component a template sets, and the status it sets it to. Only maintenance sets under_maintenance.
CREATE TABLE template_components (
  template_id TEXT NOT NULL REFERENCES templates(id) ON DELETE CASCADE,
  component_id TEXT NOT NULL REFERENCES components(id),
  status TEXT NOT NULL CHECK (status IN ('operational', 'degraded_performance', 'partial_outage', 'major_outage')),
  PRIMARY KEY (template_id, component_id)
);

-- An incident: a draft until published, then open until resolved. Never reopened.
-- App rule (R4): status moves forward only (investigating, identified, monitoring, resolved); steps can be skipped.
-- App rule: only drafts can be deleted, and the number of a deleted draft is not reused.
CREATE TABLE incidents (
  id TEXT PRIMARY KEY,
  number INTEGER NOT NULL UNIQUE CHECK (number >= 1), -- shown as INC-0013; given when the draft is created
  title TEXT NOT NULL,
  status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'investigating', 'identified', 'monitoring', 'resolved')),
  impact TEXT NOT NULL DEFAULT 'minor' CHECK (impact IN ('none', 'minor', 'major', 'critical')),
  started_at TIMESTAMP, -- set when it is published
  resolved_at TIMESTAMP,
  postmortem TEXT CHECK (length(postmortem) <= 20000), -- Markdown; resolved incidents only
  postmortem_at TIMESTAMP, -- when the postmortem was last added or edited
  created_by TEXT REFERENCES team_members(id), -- NULL when automation opened it
  related_to TEXT REFERENCES incidents(id), -- an earlier incident this one follows on from
  CHECK ((status = 'draft' AND started_at IS NULL) OR (status <> 'draft' AND started_at IS NOT NULL)),
  CHECK ((status = 'resolved' AND resolved_at IS NOT NULL) OR (status <> 'resolved' AND resolved_at IS NULL)),
  CHECK (postmortem IS NULL OR status = 'resolved')
);

-- One update on an incident. The text of a draft is its first update with published_at NULL.
-- App rule (R5): an admin can correct the message after publishing; the original stays in the activity log.
CREATE TABLE incident_updates (
  id TEXT PRIMARY KEY,
  incident_id TEXT NOT NULL REFERENCES incidents(id) ON DELETE CASCADE, -- cascade only matters for deleted drafts
  status TEXT NOT NULL CHECK (status IN ('investigating', 'identified', 'monitoring', 'resolved')),
  message TEXT NOT NULL CHECK (length(message) BETWEEN 10 AND 2000),
  notify BOOLEAN NOT NULL, -- email subscribers of the affected components of the incident (R9)
  published_at TIMESTAMP, -- NULL only for the text of a draft
  author_id TEXT REFERENCES team_members(id) -- NULL for automation; never shown publicly
);

-- A component status set by one incident update (the component_statuses list of the update).
CREATE TABLE incident_update_components (
  update_id TEXT NOT NULL REFERENCES incident_updates(id) ON DELETE CASCADE,
  component_id TEXT NOT NULL REFERENCES components(id),
  status TEXT NOT NULL CHECK (status IN ('operational', 'degraded_performance', 'partial_outage', 'major_outage')),
  PRIMARY KEY (update_id, component_id)
);

-- A scheduled maintenance window (Maintenance in the spec), numbered M-0001.
-- App rule (R7): the every-minute job starts and completes it on time and sends a reminder 1 hour before.
CREATE TABLE maintenance_windows (
  id TEXT PRIMARY KEY,
  number INTEGER NOT NULL UNIQUE CHECK (number >= 1), -- shown as M-0003
  title TEXT NOT NULL,
  message TEXT, -- optional
  starts_at TIMESTAMP NOT NULL,
  ends_at TIMESTAMP NOT NULL,
  status TEXT NOT NULL DEFAULT 'scheduled' CHECK (status IN ('scheduled', 'in_progress', 'completed', 'cancelled')),
  notify BOOLEAN NOT NULL,
  CHECK (ends_at > starts_at)
);

-- A component a maintenance window affects. App rule: at least one per window.
CREATE TABLE maintenance_components (
  maintenance_id TEXT NOT NULL REFERENCES maintenance_windows(id) ON DELETE CASCADE,
  component_id TEXT NOT NULL REFERENCES components(id),
  PRIMARY KEY (maintenance_id, component_id)
);

-- One change of the status of a component. Append-only; uptime and the 90-day bars come only from this log (R2).
CREATE TABLE status_changes (
  id TEXT PRIMARY KEY,
  component_id TEXT NOT NULL REFERENCES components(id),
  status TEXT NOT NULL CHECK (status IN ('operational', 'degraded_performance', 'partial_outage', 'major_outage', 'under_maintenance')),
  at TIMESTAMP NOT NULL,
  incident_id TEXT REFERENCES incidents(id),
  maintenance_id TEXT REFERENCES maintenance_windows(id),
  actor TEXT NOT NULL, -- a team member id, 'automation' or 'schedule'
  CHECK (incident_id IS NULL OR maintenance_id IS NULL)
);
CREATE INDEX status_changes_component_at ON status_changes (component_id, at);

-- An email address subscribed to updates. Removing a subscriber deletes the row.
-- App rule (R8): double opt-in; the confirmation link expires 7 days after confirm_sent_at.
CREATE TABLE subscribers (
  id TEXT PRIMARY KEY,
  email TEXT NOT NULL UNIQUE CHECK (email = lower(email)), -- stored lowercase
  all_components BOOLEAN NOT NULL DEFAULT FALSE, -- TRUE: every component, and subscriber_components is empty
  confirm_token TEXT UNIQUE, -- generated by the app
  confirm_sent_at TIMESTAMP,
  confirmed_at TIMESTAMP, -- only confirmed subscribers are emailed
  manage_token TEXT UNIQUE, -- for the manage and one-click unsubscribe links; generated by the app
  unsubscribed_at TIMESTAMP,
  created_ip TEXT
);

-- A component a subscriber follows when all_components is FALSE (component_ids in the spec).
CREATE TABLE subscriber_components (
  subscriber_id TEXT NOT NULL REFERENCES subscribers(id) ON DELETE CASCADE,
  component_id TEXT NOT NULL REFERENCES components(id),
  PRIMARY KEY (subscriber_id, component_id)
);

-- One entry in the activity log. Append-only (R12).
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  at TIMESTAMP NOT NULL,
  actor TEXT NOT NULL, -- a team member id, 'schedule', 'automation', 'visitor' or 'outbox'
  type TEXT NOT NULL,
  data TEXT NOT NULL DEFAULT '{}' -- a JSON object stored as text
);

-- One email in the outbox, written before it is sent. Subscriber emails keep only the address, so removing a subscriber leaves them.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  kind TEXT NOT NULL,
  to_email TEXT NOT NULL,
  subject TEXT NOT NULL,
  body TEXT NOT NULL,
  headers TEXT, -- extra headers such as List-Unsubscribe, as text
  created_at TIMESTAMP NOT NULL,
  incident_id TEXT REFERENCES incidents(id),
  maintenance_id TEXT REFERENCES maintenance_windows(id),
  attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts BETWEEN 0 AND 3), -- at most 3 send attempts per email
  status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'sent', 'failed', 'logged')),
  error TEXT,
  CHECK (incident_id IS NULL OR maintenance_id IS NULL)
);
CREATE INDEX notifications_status ON notifications (status);
```

## Seed data

Loads section 14: settings, 3 team members, 2 groups, 5 components, 3 templates, INC-0013 and INC-0014 with their 8 updates, M-0003, 9 status changes and 5 subscribers. Left out or filled by stated choice: the 3 logged scheduled-maintenance emails (the spec gives no body, kind or headers); activity log events (none are listed); tokens and page_url (generated or set per install, so NULL); INC-0014's resolved message (none given, so INC-0013's text is reused); notify on the seed updates (not given, set TRUE); component creation (1 Jul 2026, since the spec only says more than 90 days ago); and times of day the spec omits (00:00 CDT).

## Load it

```sh
# SQLite
curl -s https://personalsoftwarefactory.com/schemas/status-page.sql https://personalsoftwarefactory.com/schemas/status-page-seed.sql | sqlite3 status_page.db
# PostgreSQL
createdb status_page && curl -s https://personalsoftwarefactory.com/schemas/status-page.sql https://personalsoftwarefactory.com/schemas/status-page-seed.sql | psql -v ON_ERROR_STOP=1 status_page
```

## Design decisions

### Uptime comes from an append-only status log

status_changes gets a row for every status change and rows are never edited (R2), because section 6 computes uptime and each day's bar only from this log. The build test found the spec didn't say what a component's status was before its first row, so every component now gets an operational row when it is created, as the seed does. Uptime itself needs date arithmetic, which differs between engines, so it belongs in the app, not in portable SQL. (This point comes from a gap the blueprint's build test found.)

### An update's component statuses are a child table

IncidentUpdate's component_statuses is a list of component and status pairs, stored as incident_update_components. R9 emails subscribers of every component any published update of the incident has set, which the build test found had first been read as only the latest update's components; with a child table that is one join. A CHECK keeps under_maintenance out, since only maintenance sets it (section 7). (This point comes from a gap the blueprint's build test found.)

### A draft's text is its first update

There is no draft message column on incidents. The build test found a draft had nowhere to keep its message, and section 5 now says a draft's text is its first IncidentUpdate with published_at NULL. The incident's number is given when the draft is created and started_at is set on publishing, which a CHECK ties to the status. (This point comes from a gap the blueprint's build test found.)

### Subscribers follow all components or a list

all_components is a boolean and subscriber_components holds the list when it is FALSE. R9 sends each update once per subscriber who follows all components or at least one affected component, and unconfirmed or unsubscribed addresses get nothing. Outbox rows keep only to_email with no foreign key, so removing a subscriber (screen 7) deletes the row and leaves emails already written.

### Postmortems only on resolved incidents

postmortem is Markdown up to 20,000 characters and a CHECK allows it only when the status is resolved, as section 5 says. The build test found postmortems had no rules and no time; postmortem_at now records when it was posted, for the feed. (This point comes from a gap the blueprint's build test found.)

### Current status is stored, but R6 defines it

components.status holds the status the page shows, so the page and the JSON API read it directly. R6 says it is always the worst of the latest status each open incident set for it and under maintenance for each running window, or operational; the app must recompute it on every incident or maintenance change, which no portable constraint can do.

## Example queries

### The banner: overall status of visible components

```sql
SELECT CASE MAX(CASE status
      WHEN 'major_outage' THEN 5 WHEN 'partial_outage' THEN 4 WHEN 'degraded_performance' THEN 3
      WHEN 'under_maintenance' THEN 2 ELSE 1 END)
    WHEN 5 THEN 'Major outage' WHEN 4 THEN 'Partial outage' WHEN 3 THEN 'Degraded performance'
    WHEN 2 THEN 'Under maintenance' ELSE 'All systems operational' END AS banner,
  COUNT(*) AS visible_components
FROM components
WHERE hidden = FALSE;
```

On the seed data: 1 row; All systems operational, from 5 visible components.

### Components by group with their current status

```sql
SELECT g.name AS group_name, c.name AS component, c.status, COALESCE(c.description, '') AS description
FROM components c
JOIN component_groups g ON g.id = c.group_id
WHERE c.hidden = FALSE
ORDER BY g.position, c.position;
```

On the seed data: 5 rows; Payments in Delivery is operational with the description Processed by Stripe.

### Incident history with update counts

```sql
SELECT i.number, i.title, i.impact, i.status,
  (SELECT COUNT(*) FROM incident_updates u WHERE u.incident_id = i.id AND u.published_at IS NOT NULL) AS updates,
  (SELECT u.status FROM incident_updates u WHERE u.incident_id = i.id AND u.published_at IS NOT NULL
   ORDER BY u.published_at DESC LIMIT 1) AS latest_status
FROM incidents i
WHERE i.status <> 'draft'
ORDER BY i.started_at DESC;
```

On the seed data: 2 rows; INC-0014 (number 14), Invoice emails delayed, resolved after 4 updates, comes first.

### Who gets emailed about an incident (R9)

```sql
SELECT s.email
FROM subscribers s
WHERE s.confirmed_at IS NOT NULL
  AND s.unsubscribed_at IS NULL
  AND (s.all_components = TRUE
       OR EXISTS (
         SELECT 1
         FROM subscriber_components sc
         JOIN incident_update_components iuc ON iuc.component_id = sc.component_id
         JOIN incident_updates u ON u.id = iuc.update_id
         WHERE sc.subscriber_id = s.id
           AND u.incident_id = 'inc-0013'
           AND u.published_at IS NOT NULL))
ORDER BY s.email;
```

On the seed data, for INC-0013: 3 rows; ana@studio.example, lee@agency.example and sam@clientco.example.

### Upcoming maintenance and its components

```sql
SELECT m.number, m.title, m.status, c.name AS component
FROM maintenance_windows m
JOIN maintenance_components mc ON mc.maintenance_id = m.id
JOIN components c ON c.id = mc.component_id
WHERE m.status IN ('scheduled', 'in_progress')
ORDER BY m.starts_at, c.position;
```

On the seed data: 2 rows; M-0003 (number 3), Database upgrade, scheduled for Dashboard and API.

## What was not tested

- MySQL, MariaDB, SQL Server and Oracle. The file avoids engine-specific syntax, but it was not run on them.
- Other versions of SQLite and PostgreSQL than the two named above.
- PostgreSQL as a server. The PostgreSQL run used PGlite, which is PostgreSQL compiled to run in-process.
- Production load. The check loads the seed rows and runs the example queries; it says nothing about performance with real volumes.
- Migrations. This is a schema for a new database, not a path from an existing one.

## The blueprint

This schema is section 5 of the [Status Page blueprint](https://personalsoftwarefactory.com/blueprints/status-page), which also has the business rules, the screens, the phased build prompts and the acceptance checks. Paste-ready spec: https://personalsoftwarefactory.com/blueprints/status-page/blueprint.md
