# Customer feedback management system database schema

Source: https://personalsoftwarefactory.com/schemas/feedback-inbox
Updated: 2026-12-04

> Eleven tables. feedback holds each customer's own words and links to at most one theme; themes carries the roadmap status once promoted; votes allows one vote per account per theme. Evidence, accounts and MRR are computed from linked feedback every time, counting each account's MRR once per theme, and follow_ups lists the accounts to tell when a theme ships.

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

Files: [feedback-inbox.sql](https://personalsoftwarefactory.com/schemas/feedback-inbox.sql) · [feedback-inbox-seed.sql](https://personalsoftwarefactory.com/schemas/feedback-inbox-seed.sql) · [the Customer Feedback Inbox blueprint](https://personalsoftwarefactory.com/blueprints/feedback-inbox)

## Relationships

- customer_domains.customer_id references customers.id: each customer_domains row points to exactly one customers row, and one customers row can have many customer_domains rows pointing to it.
- themes.created_by references people.id: each themes row points to exactly one people row, and one people row can have many themes rows pointing to it.
- themes.owner_id references people.id: each themes row points to at most one people row, and one people row can have many themes rows pointing to it.
- feedback.customer_id references customers.id: each feedback row points to at most one customers row, and one customers row can have many feedback rows pointing to it.
- feedback.captured_by references people.id: each feedback row points to at most one people row, and one people row can have many feedback rows pointing to it.
- feedback.theme_id references themes.id: each feedback row points to at most one themes row, and one themes row can have many feedback rows pointing to it.
- votes.theme_id references themes.id: each votes row points to exactly one themes row, and one themes row can have many votes rows pointing to it.
- votes.customer_id references customers.id: each votes row points to exactly one customers row, and one customers row can have many votes rows pointing to it.
- votes.recorded_by references people.id: each votes row points to exactly one people row, and one people row can have many votes rows pointing to it.
- status_changes.theme_id references themes.id: each status_changes row points to exactly one themes row, and one themes row can have many status_changes rows pointing to it.
- status_changes.actor_id references people.id: each status_changes row points to exactly one people row, and one people row can have many status_changes rows pointing to it.
- follow_ups.theme_id references themes.id: each follow_ups row points to exactly one themes row, and one themes row can have many follow_ups rows pointing to it.
- follow_ups.shipped_change_id references status_changes.id: each follow_ups row points to exactly one status_changes row, and one status_changes row can have many follow_ups rows pointing to it.
- follow_ups.customer_id references customers.id: each follow_ups row points to exactly one customers row, and one customers row can have many follow_ups rows pointing to it.
- follow_ups.done_by references people.id: each follow_ups row points to at most one people row, and one people row can have many follow_ups rows pointing to it.
- events.actor_id references people.id: each events row points to at most one people row, and one people row can have many events rows pointing to it.
- events.theme_id references themes.id: each events row points to at most one themes row, and one themes row can have many events rows pointing to it.
- notifications.person_id references people.id: each notifications row points to at most one people row, and one people row can have many notifications rows pointing to it.
- notifications.theme_id references themes.id: each notifications row points to at most one themes row, and one themes row can have many notifications rows pointing to it.

## Tables

Also described as: feature request tracker database design, product feedback database tables, voice of the customer SQL schema.

### people

A team member who can sign in, admin or not. Implements: Person.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  |  |
| `email` | TEXT | no |  | Unique | stored lowercase Check: `email = LOWER(email)` |
| `is_admin` | BOOLEAN | no | `FALSE` |  |  |
| `active` | BOOLEAN | no | `TRUE` |  |  |

### settings

The single row with the company name, time zone and follow-up email template. Implements: Settings.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | INTEGER | no | `1` | Primary key | always 1, so there can only be one row Check: `id = 1` |
| `company_name` | TEXT | no |  |  | Check: `LENGTH(company_name) <= 60` |
| `time_zone` | TEXT | no | `'America/New_York'` |  | IANA name |
| `follow_up_template` | TEXT | no |  |  | may use {contact_first_name}, {theme_name}, {company_name} Check: `LENGTH(follow_up_template) <= 2000` |

### customers

A customer account with its current MRR in cents. Implements: Customer.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | unique ignoring case (index below) Check: `LENGTH(name) BETWEEN 1 AND 80` |
| `mrr_cents` | INTEGER | no | `0` |  | Check: `mrr_cents >= 0` |
| `archived` | BOOLEAN | no | `FALSE` |  |  |

- Unique index `customers_name_unique` on (LOWER(name))
- App rule (section 12): archived customers can't vote, receive new captures or join a new follow-up list.

### customer_domains

One email domain that belongs to one customer, used to match inbound feedback. Implements: child table of Customer.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `domain` | TEXT | no |  | Primary key | e.g. acme.example; belongs to at most one customer Check: `domain = LOWER(domain) AND domain NOT LIKE '%@%'` |
| `customer_id` | TEXT | no |  | References customers.id |  |

- Index `customer_domains_customer` on (customer_id)

### themes

A request or problem that feedback is grouped under, with its owner and roadmap status once promoted. Implements: Theme.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | unique ignoring case and surrounding spaces (index below) Check: `LENGTH(TRIM(name)) BETWEEN 3 AND 80` |
| `description` | TEXT | yes |  |  | Check: `description IS NULL OR LENGTH(description) <= 1000` |
| `created_by` | TEXT | no |  | References people.id |  |
| `created_at` | TIMESTAMP | no | `CURRENT_TIMESTAMP` |  |  |
| `promoted_at` | TIMESTAMP | yes |  |  | null until promoted to the roadmap; never un-promoted |
| `owner_id` | TEXT | yes |  | References people.id | required once promoted |
| `status` | TEXT | yes |  |  | null until promoted Check: `status IN ('under_review', 'planned', 'in_progress', 'shipped', 'not_planned')` |

- Table check: `promoted_at IS NULL OR owner_id IS NOT NULL`
- Table check: `(promoted_at IS NULL AND status IS NULL) OR (promoted_at IS NOT NULL AND status IS NOT NULL)`
- Unique index `themes_name_unique` on (LOWER(TRIM(name)))
- App rule (R7): promotion needs at least one linked feedback and an active owner.

### feedback

One piece of customer feedback in their own words, with its source, sender, account and state. Implements: Feedback.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `customer_id` | TEXT | yes |  | References customers.id | null: Needs customer |
| `source` | TEXT | no |  |  | Check: `source IN ('email', 'call', 'ticket', 'chat', 'in_app', 'other')` |
| `from_name` | TEXT | yes |  |  | Check: `from_name IS NULL OR LENGTH(from_name) <= 100` |
| `from_email` | TEXT | yes |  |  | stored lowercase Check: `from_email IS NULL OR (from_email = LOWER(from_email) AND from_email LIKE '%_@_%')` |
| `quote` | TEXT | no |  |  | never rewritten Check: `LENGTH(TRIM(quote)) BETWEEN 10 AND 3000` |
| `received_at` | TIMESTAMP | no | `CURRENT_TIMESTAMP` |  |  |
| `captured_by` | TEXT | yes |  | References people.id | null for inbound |
| `external_id` | TEXT | yes |  | Unique | set by the inbound endpoint Check: `external_id IS NULL OR LENGTH(external_id) <= 200` |
| `state` | TEXT | no | `'inbox'` |  | Check: `state IN ('inbox', 'linked', 'dismissed')` |
| `theme_id` | TEXT | yes |  | References themes.id | one theme at most (R2) |
| `dismiss_reason` | TEXT | yes |  |  | Check: `dismiss_reason IS NULL OR LENGTH(dismiss_reason) BETWEEN 5 AND 300` |
| `created_at` | TIMESTAMP | no | `CURRENT_TIMESTAMP` |  |  |

- Table check: `(state = 'linked' AND theme_id IS NOT NULL) OR (state <> 'linked' AND theme_id IS NULL)`
- Table check: `(state = 'dismissed' AND dismiss_reason IS NOT NULL) OR (state <> 'dismissed' AND dismiss_reason IS NULL)`
- Table check: `state <> 'linked' OR customer_id IS NOT NULL`
- Index `feedback_theme` on (theme_id)
- Index `feedback_customer` on (customer_id)
- App rule (R4): received_at is never in the future; the customer is not archived at capture.

### votes

One customer account's vote for one theme. Implements: Vote.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `theme_id` | TEXT | no |  | Primary key (part); References themes.id |  |
| `customer_id` | TEXT | no |  | Primary key (part); References customers.id |  |
| `recorded_by` | TEXT | no |  | References people.id |  |
| `created_at` | TIMESTAMP | no | `CURRENT_TIMESTAMP` |  |  |

### status_changes

One append-only roadmap decision on a theme, with its note. Implements: StatusChange.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `theme_id` | TEXT | no |  | References themes.id |  |
| `from_status` | TEXT | yes |  |  | null for the promotion Check: `from_status IN ('under_review', 'planned', 'in_progress', 'shipped', 'not_planned')` |
| `to_status` | TEXT | no |  |  | Check: `to_status IN ('under_review', 'planned', 'in_progress', 'shipped', 'not_planned')` |
| `note` | TEXT | no |  |  | Check: `LENGTH(note) BETWEEN 5 AND 500` |
| `actor_id` | TEXT | no |  | References people.id |  |
| `created_at` | TIMESTAMP | no | `CURRENT_TIMESTAMP` |  |  |

- Table check: `from_status IS NULL OR from_status <> to_status`
- Index `status_changes_theme` on (theme_id, created_at)
- App rule (R8): made by the theme owner or an admin.

### follow_ups

One account to tell about one shipment of a theme, and whether that was done. Implements: FollowUp.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `theme_id` | TEXT | no |  | References themes.id |  |
| `shipped_change_id` | TEXT | no |  | References status_changes.id | the change that moved the theme to shipped |
| `customer_id` | TEXT | no |  | References customers.id |  |
| `status` | TEXT | no | `'pending'` |  | Check: `status IN ('pending', 'emailed', 'contacted', 'cancelled')` |
| `done_by` | TEXT | yes |  | References people.id |  |
| `done_at` | TIMESTAMP | yes |  |  |  |
| `note` | TEXT | yes |  |  | how they were contacted Check: `note IS NULL OR LENGTH(note) <= 300` |

- Unique together: `shipped_change_id`, `customer_id`
- Table check: `status NOT IN ('emailed', 'contacted') OR (done_by IS NOT NULL AND done_at IS NOT NULL)`
- Table check: `status <> 'contacted' OR COALESCE(LENGTH(note), 0) >= 3`
- App rule (R9): created when the theme enters shipped; pending ones become cancelled when it leaves shipped.
- App rule (R10): only the theme owner or an admin marks one emailed or contacted, once.

### events

One append-only activity entry about feedback or a theme. Implements: Event.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `actor_id` | TEXT | yes |  | References people.id | null for inbound and the system |
| `feedback_id` | TEXT | yes |  |  |  |
| `theme_id` | TEXT | yes |  | References themes.id |  |
| `type` | TEXT | no |  |  | Check: `type IN ('captured', 'inbound_received', 'customer_assigned', 'linked', 'unlinked', 'dismissed', 'restored', 'theme_created', 'vote_added', 'vote_removed', 'promoted', 'status_changed', 'owner_changed', 'follow_up_emailed', 'follow_up_contacted', 'feedback_deleted', 'customer_changed')` |
| `data` | TEXT | yes |  |  | JSON text; cancelled follow-ups are listed in the status_changed event that left shipped |
| `created_at` | TIMESTAMP | no | `CURRENT_TIMESTAMP` |  |  |

- Index `events_theme` on (theme_id, created_at)

### notifications

One email in the outbox, with its send status. Implements: Notification.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `kind` | TEXT | no |  |  |  |
| `to_email` | TEXT | no |  |  |  |
| `person_id` | TEXT | yes |  | References people.id | null for customer contacts |
| `theme_id` | TEXT | yes |  | References themes.id |  |
| `subject` | TEXT | no |  |  |  |
| `body` | TEXT | no |  |  | plain text |
| `status` | TEXT | no | `'pending'` |  | logged: no email provider configured Check: `status IN ('pending', 'sent', 'logged', 'failed')` |
| `error` | TEXT | yes |  |  |  |
| `created_at` | TIMESTAMP | no | `CURRENT_TIMESTAMP` |  |  |
| `sent_at` | TIMESTAMP | yes |  |  |  |

- App rule (section 10): failed sends are retried up to 5 times after the first attempt; pending for 15 minutes counts as failed.

## The SQL

```sql
-- Customer Feedback Inbox database schema
-- Source: https://personalsoftwarefactory.com/blueprints/feedback-inbox (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.

-- A team member who can sign in.
CREATE TABLE people (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT NOT NULL UNIQUE CHECK (email = LOWER(email)), -- stored lowercase
  is_admin BOOLEAN NOT NULL DEFAULT FALSE,
  active BOOLEAN NOT NULL DEFAULT TRUE
);

-- The single settings row.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY DEFAULT 1 CHECK (id = 1), -- always 1, so there can only be one row
  company_name TEXT NOT NULL CHECK (LENGTH(company_name) <= 60),
  time_zone TEXT NOT NULL DEFAULT 'America/New_York', -- IANA name
  follow_up_template TEXT NOT NULL CHECK (LENGTH(follow_up_template) <= 2000) -- may use {contact_first_name}, {theme_name}, {company_name}
);

-- A customer account.
-- App rule (section 12): archived customers can't vote, receive new captures or join a new follow-up list.
CREATE TABLE customers (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 1 AND 80), -- unique ignoring case (index below)
  mrr_cents INTEGER NOT NULL DEFAULT 0 CHECK (mrr_cents >= 0),
  archived BOOLEAN NOT NULL DEFAULT FALSE
);

CREATE UNIQUE INDEX customers_name_unique ON customers (LOWER(name));

-- One email domain of a customer (Customer.domains in the spec). A customer may have none.
CREATE TABLE customer_domains (
  domain TEXT PRIMARY KEY CHECK (domain = LOWER(domain) AND domain NOT LIKE '%@%'), -- e.g. acme.example; belongs to at most one customer
  customer_id TEXT NOT NULL REFERENCES customers(id)
);

CREATE INDEX customer_domains_customer ON customer_domains (customer_id);

-- A theme: a request or problem that feedback is grouped under. Never deleted.
-- App rule (R7): promotion needs at least one linked feedback and an active owner.
CREATE TABLE themes (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (LENGTH(TRIM(name)) BETWEEN 3 AND 80), -- unique ignoring case and surrounding spaces (index below)
  description TEXT CHECK (description IS NULL OR LENGTH(description) <= 1000),
  created_by TEXT NOT NULL REFERENCES people(id),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  promoted_at TIMESTAMP, -- null until promoted to the roadmap; never un-promoted
  owner_id TEXT REFERENCES people(id), -- required once promoted
  status TEXT CHECK (status IN ('under_review', 'planned', 'in_progress', 'shipped', 'not_planned')), -- null until promoted
  CHECK (promoted_at IS NULL OR owner_id IS NOT NULL),
  CHECK ((promoted_at IS NULL AND status IS NULL) OR (promoted_at IS NOT NULL AND status IS NOT NULL))
);

CREATE UNIQUE INDEX themes_name_unique ON themes (LOWER(TRIM(name)));

-- One piece of feedback: a customer's own words. Never edited after capture (R1).
-- App rule (R4): received_at is never in the future; the customer is not archived at capture.
CREATE TABLE feedback (
  id TEXT PRIMARY KEY,
  customer_id TEXT REFERENCES customers(id), -- null: Needs customer
  source TEXT NOT NULL CHECK (source IN ('email', 'call', 'ticket', 'chat', 'in_app', 'other')),
  from_name TEXT CHECK (from_name IS NULL OR LENGTH(from_name) <= 100),
  from_email TEXT CHECK (from_email IS NULL OR (from_email = LOWER(from_email) AND from_email LIKE '%_@_%')), -- stored lowercase
  quote TEXT NOT NULL CHECK (LENGTH(TRIM(quote)) BETWEEN 10 AND 3000), -- never rewritten
  received_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  captured_by TEXT REFERENCES people(id), -- null for inbound
  external_id TEXT UNIQUE CHECK (external_id IS NULL OR LENGTH(external_id) <= 200), -- set by the inbound endpoint
  state TEXT NOT NULL DEFAULT 'inbox' CHECK (state IN ('inbox', 'linked', 'dismissed')),
  theme_id TEXT REFERENCES themes(id), -- one theme at most (R2)
  dismiss_reason TEXT CHECK (dismiss_reason IS NULL OR LENGTH(dismiss_reason) BETWEEN 5 AND 300),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CHECK ((state = 'linked' AND theme_id IS NOT NULL) OR (state <> 'linked' AND theme_id IS NULL)), -- theme only when linked
  CHECK ((state = 'dismissed' AND dismiss_reason IS NOT NULL) OR (state <> 'dismissed' AND dismiss_reason IS NULL)), -- reason only when dismissed
  CHECK (state <> 'linked' OR customer_id IS NOT NULL) -- R3: evidence needs an account
);

CREATE INDEX feedback_theme ON feedback (theme_id);
CREATE INDEX feedback_customer ON feedback (customer_id);

-- One customer account's vote for a theme. A vote never adds evidence or MRR.
CREATE TABLE votes (
  theme_id TEXT NOT NULL REFERENCES themes(id),
  customer_id TEXT NOT NULL REFERENCES customers(id),
  recorded_by TEXT NOT NULL REFERENCES people(id),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (theme_id, customer_id) -- one vote per account per theme (R6)
);

-- One status decision on a promoted theme. Append-only.
-- App rule (R8): made by the theme owner or an admin.
CREATE TABLE status_changes (
  id TEXT PRIMARY KEY,
  theme_id TEXT NOT NULL REFERENCES themes(id),
  from_status TEXT CHECK (from_status IN ('under_review', 'planned', 'in_progress', 'shipped', 'not_planned')), -- null for the promotion
  to_status TEXT NOT NULL CHECK (to_status IN ('under_review', 'planned', 'in_progress', 'shipped', 'not_planned')),
  note TEXT NOT NULL CHECK (LENGTH(note) BETWEEN 5 AND 500),
  actor_id TEXT NOT NULL REFERENCES people(id),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CHECK (from_status IS NULL OR from_status <> to_status) -- R8: a different status
);

CREATE INDEX status_changes_theme ON status_changes (theme_id, created_at);

-- One account to tell about one shipment of a theme.
-- App rule (R9): created when the theme enters shipped; pending ones become cancelled when it leaves shipped.
-- App rule (R10): only the theme owner or an admin marks one emailed or contacted, once.
CREATE TABLE follow_ups (
  id TEXT PRIMARY KEY,
  theme_id TEXT NOT NULL REFERENCES themes(id),
  shipped_change_id TEXT NOT NULL REFERENCES status_changes(id), -- the change that moved the theme to shipped
  customer_id TEXT NOT NULL REFERENCES customers(id),
  status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'emailed', 'contacted', 'cancelled')),
  done_by TEXT REFERENCES people(id),
  done_at TIMESTAMP,
  note TEXT CHECK (note IS NULL OR LENGTH(note) <= 300), -- how they were contacted
  UNIQUE (shipped_change_id, customer_id),
  CHECK (status NOT IN ('emailed', 'contacted') OR (done_by IS NOT NULL AND done_at IS NOT NULL)),
  CHECK (status <> 'contacted' OR COALESCE(LENGTH(note), 0) >= 3) -- R10: Mark contacted needs a note
);

-- One entry in the activity log. Append-only, never updated or deleted (R15).
-- feedback_id has no foreign key on purpose: R14 deletes feedback, and its feedback_deleted event keeps the id.
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  actor_id TEXT REFERENCES people(id), -- null for inbound and the system
  feedback_id TEXT,
  theme_id TEXT REFERENCES themes(id),
  type TEXT NOT NULL CHECK (type IN ('captured', 'inbound_received', 'customer_assigned', 'linked', 'unlinked', 'dismissed', 'restored', 'theme_created', 'vote_added', 'vote_removed', 'promoted', 'status_changed', 'owner_changed', 'follow_up_emailed', 'follow_up_contacted', 'feedback_deleted', 'customer_changed')),
  data TEXT, -- JSON text; cancelled follow-ups are listed in the status_changed event that left shipped
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX events_theme ON events (theme_id, created_at);

-- One email in the outbox, written before it is sent.
-- App rule (section 10): failed sends are retried up to 5 times after the first attempt; pending for 15 minutes counts as failed.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  kind TEXT NOT NULL,
  to_email TEXT NOT NULL,
  person_id TEXT REFERENCES people(id), -- null for customer contacts
  theme_id TEXT REFERENCES themes(id),
  subject TEXT NOT NULL,
  body TEXT NOT NULL, -- plain text
  status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'sent', 'logged', 'failed')), -- logged: no email provider configured
  error TEXT,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  sent_at TIMESTAMP
);
```

## Seed data

Loads section 14 with T fixed to Wed 14 Oct 2026: 5 people, the settings row with the follow-up template, 4 customers and their 4 domains, 3 themes, feedback F1 to F5, 2 votes, the 5 status changes, Ridgeway's pending follow-up for CSV export, and 15 events for the captures, inbound items, theme creations, promotions, status changes and votes. The spec names who did each of those but not who linked F1 to F4, so the four linked events are left out rather than given a made-up actor. Received dates are midnight team time as R4 defines; theme creation dates (the day of each theme's first feedback), vote dates (start of T) and times of day are placeholders the spec doesn't give. The outbox is empty, as the spec says.

## Load it

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

## Design decisions

### Theme metrics are computed, never stored

Section 6 computes Evidence, Accounts, MRR and Votes from the rows every time. MRR sums each distinct account's current mrr_cents once per theme, so two quotes from Acme add $2,400 once, and a vote never adds evidence or MRR. A stored running total would go stale the moment an admin corrects an account's MRR (R12).

### Feedback state, theme and reason must agree

CHECK constraints require theme_id exactly when state is linked, dismiss_reason exactly when state is dismissed, and a customer before anything is linked (R3: evidence needs an account). Linking to another theme replaces theme_id, so a piece of feedback is evidence for one theme at most (R2).

### Domains are a child table keyed by the domain

Section 5 says each domain belongs to at most one customer and a customer may have none. customer_domains uses the domain as its primary key, which enforces that rule across customers, and the inbound endpoint (section 11) matches a sender's exact domain with one indexed lookup. A comma-separated column could not stop two customers claiming acme.example.

### Names are unique ignoring case

Customer names are unique ignoring case and theme names ignoring case and surrounding spaces (section 5, R5). Both use a unique index on LOWER(name), with TRIM for themes, so "single sign-on " cannot sit beside "Single sign-on". A plain UNIQUE would compare case on PostgreSQL and let duplicates through.

### Promotion sets owner and status together

A theme has no status until it is promoted, and needs an owner once it is (section 5). CHECK constraints keep promoted_at and status both null or both set, and require owner_id once promoted. Evidence before promotion (R7) spans tables and stays in the app.

### Events keep the id of deleted feedback

An admin can delete a piece of feedback when a customer asks for their words to be removed, and the feedback_deleted event keeps only the id, the account and the theme (R14). events.feedback_id therefore has no foreign key. Our build test found the spec had no event type for cancelled follow-ups or people and settings changes; section 5 now records cancellations in the data of the status_changed event that left Shipped and logs no people or settings changes in v1. (This point comes from a gap the blueprint's build test found.)

### A follow-up list belongs to one shipment

follow_ups references the status change that moved the theme to Shipped and is unique per (shipped_change_id, customer_id), so shipping again starts a new list while earlier ones stay as history (R9). Our build test found cancelled follow-ups could not be seen after a theme left Shipped; earlier lists now stay visible with each follow-up's status. A CHECK requires who and when for emailed and contacted, and a note for contacted (R10). (This point comes from a gap the blueprint's build test found.)

## Example queries

### Themes ranked by evidence, with accounts, MRR and votes

```sql
SELECT
  t.name,
  t.status,
  (SELECT COUNT(*) FROM feedback f WHERE f.theme_id = t.id AND f.state = 'linked') AS evidence,
  (SELECT COUNT(DISTINCT f.customer_id) FROM feedback f WHERE f.theme_id = t.id AND f.state = 'linked') AS accounts,
  (SELECT COALESCE(SUM(c.mrr_cents), 0) FROM customers c WHERE c.id IN (SELECT f.customer_id FROM feedback f WHERE f.theme_id = t.id AND f.state = 'linked')) AS mrr_cents,
  (SELECT COUNT(*) FROM votes v WHERE v.theme_id = t.id) AS votes
FROM themes t
ORDER BY evidence DESC, t.name;
```

On the seed data: 3 rows, matching section 6. Single sign-on has 2 evidence, 1 account, 240000 cents ($2,400) and 2 votes; CSV export and Slack alerts tie at 1 and sort by name.

### Inbox tab counts

```sql
SELECT
  CASE WHEN state = 'inbox' AND customer_id IS NULL THEN 'Needs customer' WHEN state = 'inbox' THEN 'Inbox' WHEN state = 'linked' THEN 'Linked' ELSE 'Dismissed' END AS tab,
  COUNT(*) AS items
FROM feedback
GROUP BY CASE WHEN state = 'inbox' AND customer_id IS NULL THEN 'Needs customer' WHEN state = 'inbox' THEN 'Inbox' WHEN state = 'linked' THEN 'Linked' ELSE 'Dismissed' END
ORDER BY tab;
```

On the seed data: 2 rows, Inbox 1 (Harbor Studio's call) and Linked 4. Tabs with no items return no row.

### Roadmap cards by lane

```sql
SELECT
  t.status,
  t.name,
  p.name AS owner,
  (SELECT COUNT(*) FROM feedback f WHERE f.theme_id = t.id AND f.state = 'linked') AS evidence
FROM themes t
JOIN people p ON p.id = t.owner_id
WHERE t.promoted_at IS NOT NULL
ORDER BY t.status, evidence DESC, t.name;
```

On the seed data: 2 rows. Single sign-on is planned, owned by Sam Okafor; CSV export is shipped, owned by Maya Chen.

### Pending follow-ups with their contact addresses

```sql
SELECT t.name AS theme, c.name AS customer, sc.created_at AS shipped_at, f.from_email
FROM follow_ups fu
JOIN themes t ON t.id = fu.theme_id
JOIN customers c ON c.id = fu.customer_id
JOIN status_changes sc ON sc.id = fu.shipped_change_id
LEFT JOIN feedback f ON f.theme_id = fu.theme_id AND f.customer_id = fu.customer_id AND f.state = 'linked' AND f.from_email IS NOT NULL
WHERE fu.status = 'pending'
ORDER BY sc.created_at, c.name, f.from_email;
```

On the seed data: 1 row, CSV export for Ridgeway, to ella@ridgeway.example. An account with no address on the theme returns a null from_email and can only be marked contacted (R10).

### A theme's status history

```sql
SELECT sc.from_status, sc.to_status, sc.note, p.name AS actor, sc.created_at
FROM status_changes sc
JOIN themes t ON t.id = sc.theme_id
JOIN people p ON p.id = sc.actor_id
WHERE t.name = 'CSV export'
ORDER BY sc.created_at;
```

On the seed data: 3 rows for CSV export, from the promotion to under_review through in_progress ("Started") to shipped ("Released in version 2.14"), all by Maya Chen.

## 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 [Customer Feedback Inbox blueprint](https://personalsoftwarefactory.com/blueprints/feedback-inbox), which also has the business rules, the screens, the phased build prompts and the acceptance checks. Paste-ready spec: https://personalsoftwarefactory.com/blueprints/feedback-inbox/blueprint.md
