# Customer testimonial management system database schema

Source: https://personalsoftwarefactory.com/schemas/testimonial-wall
Updated: 2026-12-04

> Seven tables, built around testimonials, where CHECK constraints tie status to permission: approved and published rows must have consent, a withdrawn row keeps the exact wording the customer agreed to as evidence, and only a published testimonial can be featured. A partial unique index allows one featured testimonial, and the public wall reads status, consent and withdrawn_at together. Invitations and testimonials point at each other, so only one side has a foreign key.

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

Files: [testimonial-wall.sql](https://personalsoftwarefactory.com/schemas/testimonial-wall.sql) · [testimonial-wall-seed.sql](https://personalsoftwarefactory.com/schemas/testimonial-wall-seed.sql) · [the Testimonial Wall blueprint](https://personalsoftwarefactory.com/blueprints/testimonial-wall)

## Relationships

- invitations.created_by_id references people.id: each invitations row points to exactly one people row, and one people row can have many invitations rows pointing to it.
- testimonials.invitation_id references invitations.id: each testimonials row points to at most one invitations row, and one invitations row can have at most one testimonials row pointing to it.
- testimonials.reviewed_by_id references people.id: each testimonials row points to at most one people row, and one people row can have many testimonials 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.
- 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.testimonial_id references testimonials.id: each notifications row points to at most one testimonials row, and one testimonials row can have many notifications rows pointing to it. On delete: cascade.
- notifications.invitation_id references invitations.id: each notifications row points to at most one invitations row, and one invitations row can have many notifications rows pointing to it. On delete: cascade.

## Tables

Also described as: testimonial collection database design, customer reviews and consent database tables, testimonial wall schema.

### people

A staff member: member, moderator or admin. Customers have no account. Implements: Person.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | Check: `length(trim(name)) >= 1` |
| `email` | TEXT | no |  | Unique | lowercase |
| `active` | BOOLEAN | no | `TRUE` |  |  |
| `created_at` | TIMESTAMP | no |  |  |  |
| `role` | TEXT | no |  |  | Check: `role IN ('member', 'moderator', 'admin')` |

- Table check: `email = lower(email)`
- App rule (section 10): nobody can deactivate themselves or change their own role.

### settings

The single row of settings, including the versioned permission sentence shown next to the checkbox. Implements: Settings.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | INTEGER | no |  | Primary key | keeps this table to one row Check: `id = 1` |
| `company_name` | TEXT | no |  |  | Check: `length(trim(company_name)) BETWEEN 1 AND 80` |
| `wall_title` | TEXT | no |  |  | Check: `length(trim(wall_title)) BETWEEN 1 AND 80` |
| `form_intro` | TEXT | no |  |  | Check: `length(trim(form_intro)) BETWEEN 1 AND 500` |
| `permission_text` | TEXT | no |  |  | the sentence next to the permission checkbox Check: `length(trim(permission_text)) BETWEEN 20 AND 500` |
| `permission_version` | INTEGER | no | `1` |  | Check: `permission_version >= 1` |
| `form_open` | BOOLEAN | no | `TRUE` |  |  |
| `time_zone` | TEXT | no | `'America/New_York'` |  | IANA name, for dates in emails and on public pages |

- App rule (R15): changing permission_text adds 1 to permission_version and writes a settings_changed event.

### invitations

A personal link asking one customer for a testimonial, pre-filled with the words they already used. Implements: Invitation.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `token` | TEXT | no |  | Unique | the /share/<token> link Check: `length(token) >= 24` |
| `created_by_id` | TEXT | no |  | References people.id |  |
| `name` | TEXT | no |  |  | Check: `length(trim(name)) BETWEEN 2 AND 80` |
| `email` | TEXT | no |  |  |  |
| `company` | TEXT | yes |  |  | optional, pre-fills the form |
| `job_title` | TEXT | yes |  |  | optional, pre-fills the form |
| `prefill_quote` | TEXT | yes |  |  | the words the customer already used Check: `length(trim(prefill_quote)) <= 1000` |
| `source` | TEXT | no |  |  | Check: `source IN ('email', 'call', 'chat', 'other')` |
| `source_note` | TEXT | yes |  |  | private Check: `length(trim(source_note)) <= 300` |
| `status` | TEXT | no | `'open'` |  | Check: `status IN ('open', 'completed', 'cancelled', 'expired')` |
| `created_at` | TIMESTAMP | no |  |  | the invitation email is queued then |
| `expires_at` | TIMESTAMP | no |  |  | created_at plus 14 days |
| `reminded_at` | TIMESTAMP | yes |  |  | set once, by the scheduled job after 72 hours |
| `completed_at` | TIMESTAMP | yes |  |  |  |
| `testimonial_id` | TEXT | yes |  | Unique | the testimonial it produced; no foreign key because testimonials.invitation_id points back here |

- Table check: `status <> 'completed' OR (completed_at IS NOT NULL AND testimonial_id IS NOT NULL)`
- App rule (R17): the link works only while open and before expires_at, even when the form is closed.

### testimonials

A customer's words, rating and permission evidence, with its review and publishing status. Implements: Testimonial.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `submitted_at` | TIMESTAMP | no |  |  |  |
| `updated_at` | TIMESTAMP | no |  |  |  |
| `name` | TEXT | no |  |  | Check: `length(trim(name)) BETWEEN 2 AND 80` |
| `email` | TEXT | no |  |  | never public Check: `length(trim(email)) <= 254` |
| `company` | TEXT | yes |  |  | Check: `length(trim(company)) <= 100` |
| `job_title` | TEXT | yes |  |  | labelled "Role" on the form Check: `length(trim(job_title)) <= 100` |
| `quote` | TEXT | no |  |  | plain text, line breaks kept, never rendered as HTML Check: `length(trim(quote)) BETWEEN 20 AND 1000` |
| `rating` | INTEGER | yes |  |  | NULL means no rating, never zero stars Check: `rating BETWEEN 1 AND 5` |
| `consent` | BOOLEAN | no |  |  | TRUE only when the customer ticked the box (R1, R2) |
| `consent_text` | TEXT | yes |  |  | the exact sentence agreed to; kept after a withdrawal as evidence |
| `consent_version` | INTEGER | yes |  |  |  |
| `consent_at` | TIMESTAMP | yes |  |  |  |
| `withdrawn_at` | TIMESTAMP | yes |  |  |  |
| `status` | TEXT | no | `'pending'` |  | Check: `status IN ('pending', 'approved', 'rejected', 'published', 'withdrawn')` |
| `featured` | BOOLEAN | no | `FALSE` |  |  |
| `source` | TEXT | no |  |  | Check: `source IN ('form', 'invitation')` |
| `invitation_id` | TEXT | yes |  | References invitations.id; Unique | an invitation produces at most one testimonial (R17) |
| `manage_token` | TEXT | no |  | Unique | the customer's private /t/<token> link Check: `length(manage_token) >= 24` |
| `review_note` | TEXT | yes |  |  | private; required (5 or more) on reject Check: `length(trim(review_note)) <= 300` |
| `reviewed_by_id` | TEXT | yes |  | References people.id |  |
| `reviewed_at` | TIMESTAMP | yes |  |  |  |
| `published_at` | TIMESTAMP | yes |  |  | the most recent publish |

- Table check: `(source = 'invitation') = (invitation_id IS NOT NULL)`
- Table check: `consent = FALSE OR (consent_text IS NOT NULL AND consent_version IS NOT NULL AND consent_at IS NOT NULL)`
- Table check: `consent = TRUE OR status = 'withdrawn' OR (consent_text IS NULL AND consent_version IS NULL AND consent_at IS NULL)`
- Table check: `status NOT IN ('approved', 'published') OR consent = TRUE`
- Table check: `(status = 'withdrawn') = (withdrawn_at IS NOT NULL)`
- Table check: `status <> 'withdrawn' OR (consent = FALSE AND consent_at IS NOT NULL)`
- Table check: `status NOT IN ('approved', 'published', 'rejected') OR (reviewed_by_id IS NOT NULL AND reviewed_at IS NOT NULL)`
- Table check: `status <> 'rejected' OR (review_note IS NOT NULL AND length(trim(review_note)) >= 5)`
- Table check: `status <> 'published' OR published_at IS NOT NULL`
- Table check: `featured = FALSE OR status = 'published'`
- Unique index `testimonials_one_featured` on (featured) where `featured = TRUE`. R7: at most one testimonial is featured.
- Index `testimonials_status_submitted` on (status, submitted_at)
- App rule (R12): status checks and updates happen in one transaction.

### events

One append-only history entry for a testimonial or invitation, with who acted and any note. Implements: Event.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `testimonial_id` | TEXT | yes |  |  |  |
| `invitation_id` | TEXT | yes |  |  |  |
| `created_at` | TIMESTAMP | no |  |  |  |
| `actor_type` | TEXT | no |  |  | Check: `actor_type IN ('person', 'customer', 'system')` |
| `actor_id` | TEXT | yes |  | References people.id | set when actor_type is person |
| `type` | TEXT | no |  |  | Check: `type IN ('submitted', 'approved', 'rejected', 'published', 'unpublished', 'featured', 'unfeatured', 'withdrawn', 'deleted', 'invitation_created', 'invitation_completed', 'invitation_reminded', 'invitation_cancelled', 'invitation_expired', 'settings_changed')` |
| `note` | TEXT | yes |  |  | a review or withdrawal note |
| `data` | TEXT | yes |  |  | JSON text, such as old and new permission_version |

- Table check: `(actor_type = 'person') = (actor_id IS NOT NULL)`
- Index `events_testimonial` on (testimonial_id, created_at)

### notifications

An email in the outbox, to a customer or staff member, with its status. Implements: Notification.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `to_email` | TEXT | no |  |  |  |
| `person_id` | TEXT | yes |  | References people.id | set for staff recipients |
| `testimonial_id` | TEXT | yes |  | References testimonials.id, on delete cascade | NULL for invitation and invitation_reminder |
| `invitation_id` | TEXT | yes |  | References invitations.id, on delete cascade |  |
| `reply_to` | TEXT | yes |  |  | the invitation creator's email, for invitation emails |
| `kind` | TEXT | no |  |  | Check: `kind IN ('submission_received', 'new_submission', 'invitation', 'invitation_reminder', 'published', 'withdrawal_confirmed', 'withdrawn_alert')` |
| `subject` | TEXT | no |  |  |  |
| `body` | TEXT | no |  |  | plain text |
| `status` | TEXT | no | `'queued'` |  | logged when no provider is configured Check: `status IN ('queued', 'sent', 'logged', 'failed')` |
| `created_at` | TIMESTAMP | no |  |  |  |
| `sent_at` | TIMESTAMP | yes |  |  |  |
| `error` | TEXT | yes |  |  |  |

### form_attempts

One saved form submission's hashed IP and time, for rate limiting. Implements: FormAttempt.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `ip_hash` | TEXT | no |  |  | SHA-256 of the IP plus a server secret; never the raw IP |
| `created_at` | TIMESTAMP | no |  |  |  |

- Index `form_attempts_ip_hash` on (ip_hash, created_at)

## The SQL

```sql
-- Testimonial Wall database schema
-- Source: https://personalsoftwarefactory.com/blueprints/testimonial-wall (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.
-- Text lengths are counted after trimming. Tokens are at least 24 URL-safe characters from a secure random generator.

-- A staff member. Customers never have an account.
-- App rule (section 10): nobody can deactivate themselves or change their own role.
CREATE TABLE people (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (length(trim(name)) >= 1),
  email TEXT NOT NULL UNIQUE, -- lowercase
  active BOOLEAN NOT NULL DEFAULT TRUE,
  created_at TIMESTAMP NOT NULL,
  role TEXT NOT NULL CHECK (role IN ('member', 'moderator', 'admin')),
  CHECK (email = lower(email))
);

-- Company settings. Exactly one row.
-- App rule (R15): changing permission_text adds 1 to permission_version and writes a settings_changed event.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY CHECK (id = 1), -- keeps this table to one row
  company_name TEXT NOT NULL CHECK (length(trim(company_name)) BETWEEN 1 AND 80),
  wall_title TEXT NOT NULL CHECK (length(trim(wall_title)) BETWEEN 1 AND 80),
  form_intro TEXT NOT NULL CHECK (length(trim(form_intro)) BETWEEN 1 AND 500),
  permission_text TEXT NOT NULL CHECK (length(trim(permission_text)) BETWEEN 20 AND 500), -- the sentence next to the permission checkbox
  permission_version INTEGER NOT NULL DEFAULT 1 CHECK (permission_version >= 1),
  form_open BOOLEAN NOT NULL DEFAULT TRUE,
  time_zone TEXT NOT NULL DEFAULT 'America/New_York' -- IANA name, for dates in emails and on public pages
);

-- A personal link that asks one customer for a testimonial, pre-filled with what they already said.
-- App rule (R17): the link works only while open and before expires_at, even when the form is closed.
CREATE TABLE invitations (
  id TEXT PRIMARY KEY,
  token TEXT NOT NULL UNIQUE CHECK (length(token) >= 24), -- the /share/<token> link
  created_by_id TEXT NOT NULL REFERENCES people(id),
  name TEXT NOT NULL CHECK (length(trim(name)) BETWEEN 2 AND 80),
  email TEXT NOT NULL,
  company TEXT, -- optional, pre-fills the form
  job_title TEXT, -- optional, pre-fills the form
  prefill_quote TEXT CHECK (length(trim(prefill_quote)) <= 1000), -- the words the customer already used
  source TEXT NOT NULL CHECK (source IN ('email', 'call', 'chat', 'other')),
  source_note TEXT CHECK (length(trim(source_note)) <= 300), -- private
  status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'completed', 'cancelled', 'expired')),
  created_at TIMESTAMP NOT NULL, -- the invitation email is queued then
  expires_at TIMESTAMP NOT NULL, -- created_at plus 14 days
  reminded_at TIMESTAMP, -- set once, by the scheduled job after 72 hours
  completed_at TIMESTAMP,
  testimonial_id TEXT UNIQUE, -- the testimonial it produced; no foreign key because testimonials.invitation_id points back here
  CHECK (status <> 'completed' OR (completed_at IS NOT NULL AND testimonial_id IS NOT NULL))
);

-- A customer's testimonial. Customer wording and consent fields are never edited by staff (R3).
-- App rule (R12): status checks and updates happen in one transaction.
CREATE TABLE testimonials (
  id TEXT PRIMARY KEY,
  submitted_at TIMESTAMP NOT NULL,
  updated_at TIMESTAMP NOT NULL,
  name TEXT NOT NULL CHECK (length(trim(name)) BETWEEN 2 AND 80),
  email TEXT NOT NULL CHECK (length(trim(email)) <= 254), -- never public
  company TEXT CHECK (length(trim(company)) <= 100),
  job_title TEXT CHECK (length(trim(job_title)) <= 100), -- labelled "Role" on the form
  quote TEXT NOT NULL CHECK (length(trim(quote)) BETWEEN 20 AND 1000), -- plain text, line breaks kept, never rendered as HTML
  rating INTEGER CHECK (rating BETWEEN 1 AND 5), -- NULL means no rating, never zero stars
  consent BOOLEAN NOT NULL, -- TRUE only when the customer ticked the box (R1, R2)
  consent_text TEXT, -- the exact sentence agreed to; kept after a withdrawal as evidence
  consent_version INTEGER,
  consent_at TIMESTAMP,
  withdrawn_at TIMESTAMP,
  status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'rejected', 'published', 'withdrawn')),
  featured BOOLEAN NOT NULL DEFAULT FALSE,
  source TEXT NOT NULL CHECK (source IN ('form', 'invitation')),
  invitation_id TEXT UNIQUE REFERENCES invitations(id), -- an invitation produces at most one testimonial (R17)
  manage_token TEXT NOT NULL UNIQUE CHECK (length(manage_token) >= 24), -- the customer's private /t/<token> link
  review_note TEXT CHECK (length(trim(review_note)) <= 300), -- private; required (5 or more) on reject
  reviewed_by_id TEXT REFERENCES people(id),
  reviewed_at TIMESTAMP,
  published_at TIMESTAMP, -- the most recent publish
  CHECK ((source = 'invitation') = (invitation_id IS NOT NULL)),
  -- consent evidence is complete when given, and empty when never given
  CHECK (consent = FALSE OR (consent_text IS NOT NULL AND consent_version IS NOT NULL AND consent_at IS NOT NULL)),
  CHECK (consent = TRUE OR status = 'withdrawn' OR (consent_text IS NULL AND consent_version IS NULL AND consent_at IS NULL)),
  -- R4, R5: approved and published need consent. R8: withdrawn means consent FALSE, withdrawn_at set, not featured
  CHECK (status NOT IN ('approved', 'published') OR consent = TRUE),
  CHECK ((status = 'withdrawn') = (withdrawn_at IS NOT NULL)),
  CHECK (status <> 'withdrawn' OR (consent = FALSE AND consent_at IS NOT NULL)),
  CHECK (status NOT IN ('approved', 'published', 'rejected') OR (reviewed_by_id IS NOT NULL AND reviewed_at IS NOT NULL)),
  CHECK (status <> 'rejected' OR (review_note IS NOT NULL AND length(trim(review_note)) >= 5)),
  CHECK (status <> 'published' OR published_at IS NOT NULL),
  CHECK (featured = FALSE OR status = 'published') -- R7: only a published testimonial can be featured
);

-- R7: at most one testimonial is featured.
CREATE UNIQUE INDEX testimonials_one_featured ON testimonials (featured) WHERE featured = TRUE;
CREATE INDEX testimonials_status_submitted ON testimonials (status, submitted_at);

-- Append-only history. Never copies the customer's quote, email or name.
-- No foreign keys to testimonials or invitations: R14's deleted event keeps the old id after both rows are gone.
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  testimonial_id TEXT,
  invitation_id TEXT,
  created_at TIMESTAMP NOT NULL,
  actor_type TEXT NOT NULL CHECK (actor_type IN ('person', 'customer', 'system')),
  actor_id TEXT REFERENCES people(id), -- set when actor_type is person
  type TEXT NOT NULL CHECK (type IN ('submitted', 'approved', 'rejected', 'published', 'unpublished', 'featured', 'unfeatured', 'withdrawn', 'deleted',
    'invitation_created', 'invitation_completed', 'invitation_reminded', 'invitation_cancelled', 'invitation_expired', 'settings_changed')),
  note TEXT, -- a review or withdrawal note
  data TEXT, -- JSON text, such as old and new permission_version
  CHECK ((actor_type = 'person') = (actor_id IS NOT NULL))
);

CREATE INDEX events_testimonial ON events (testimonial_id, created_at);

-- An email in the outbox. Written first, then sent; failed or stuck rows are retried by the hourly job.
-- R14 removes a deleted testimonial's outbox rows, so both references cascade.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  to_email TEXT NOT NULL,
  person_id TEXT REFERENCES people(id), -- set for staff recipients
  testimonial_id TEXT REFERENCES testimonials(id) ON DELETE CASCADE, -- NULL for invitation and invitation_reminder
  invitation_id TEXT REFERENCES invitations(id) ON DELETE CASCADE,
  reply_to TEXT, -- the invitation creator's email, for invitation emails
  kind TEXT NOT NULL CHECK (kind IN ('submission_received', 'new_submission', 'invitation', 'invitation_reminder', 'published', 'withdrawal_confirmed', 'withdrawn_alert')),
  subject TEXT NOT NULL,
  body TEXT NOT NULL, -- plain text
  status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'sent', 'logged', 'failed')), -- logged when no provider is configured
  created_at TIMESTAMP NOT NULL,
  sent_at TIMESTAMP,
  error TEXT
);

-- One saved form submission, for rate limiting (R16: at most 5 per IP hash per 60 minutes). Pruned after 24 hours.
CREATE TABLE form_attempts (
  id TEXT PRIMARY KEY,
  ip_hash TEXT NOT NULL, -- SHA-256 of the IP plus a server secret; never the raw IP
  created_at TIMESTAMP NOT NULL
);

CREATE INDEX form_attempts_ip_hash ON form_attempts (ip_hash, created_at);
```

## Seed data

Loads all of section 14 for Northwind: 4 staff, the settings row with permission wording version 1, the 10 testimonials with their words, permission evidence and review history, Ben's completed and Nora's open invitation, and 29 events matching the history (including the two invitations' creation and Ben's completion). The spec times everything from T, the moment the seed loads; this file fixes T at 2026-10-15 12:00 UTC and gives people that created_at. Tokens must be random, so the seed holds clearly marked placeholder tokens to replace. The outbox starts empty and there are no form attempts, as the spec says.

## Load it

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

## Design decisions

### Status and permission are checked together

R4 and R5 make permission a condition of approving and publishing, and R1 and R2 say only the customer's checkbox sets consent. CHECKs make approved and published rows carry consent = TRUE with the exact consent_text, version and time, and make a row that never had consent carry none. A wrong status update therefore fails in the database, not only in the app.

### Withdrawal keeps the evidence

R8 sets consent to FALSE, withdrawn_at to now, status to withdrawn and featured to FALSE in one transaction, but keeps consent_text, consent_version and consent_at as evidence of what was agreed and when. The CHECKs follow that: status withdrawn exactly when withdrawn_at is set, and a withdrawn row must still hold its consent time. It cannot be undone; the customer submits again.

### One featured testimonial, enforced by the database

R7 allows at most one featured testimonial, only a published one, and asks for a unique index on featured where featured is true where the database supports partial indexes; both engines here do. The build test found R7 let a second moderator silently replace a featured testimonial; the spec now has the Feature request carry the one the moderator saw and refuse it if that changed, which stays in the app. (This point comes from a gap the blueprint's build test found.)

### Invitations and testimonials point at each other

A testimonial records the invitation it came from and an invitation records the testimonial it produced (section 5), which is a cycle. The foreign key sits on testimonials.invitation_id, and invitations.testimonial_id is a plain column. Both are UNIQUE, because an invitation produces at most one testimonial (R17), and a CHECK ties source = invitation to having an invitation_id.

### History survives a delete; the outbox does not

R14 lets an admin delete a rejected or withdrawn testimonial with its events, outbox rows and invitation, then write one deleted event that keeps the old id. So events has no foreign keys to testimonials or invitations, while notifications references both with ON DELETE CASCADE. The build test found a notification's testimonial had to be optional for invitation emails and the invitation's Reply-To had nowhere to live; testimonial_id is nullable and reply_to holds the creator's email. (This point comes from a gap the blueprint's build test found.)

### Tokens and IP addresses

manage_token and invitation tokens are unique and at least 24 characters, from a secure random generator (section 5), because the link is the customer's only key. form_attempts stores a SHA-256 hash of the IP plus a server secret, never the raw IP, and the hourly job prunes rows older than 24 hours.

## Example queries

### The public wall (R9 and section 9)

```sql
SELECT name, job_title, company, rating, CASE WHEN featured THEN 'featured' ELSE '' END AS featured, quote FROM testimonials WHERE status = 'published' AND consent = TRUE AND withdrawn_at IS NULL ORDER BY CASE WHEN featured THEN 0 ELSE 1 END, submitted_at DESC;
```

On the seed data: 5 rows in the spec's order (Ana Moreno featured, then Theo Grant, Hugo Brandt, Rosa Lind, Ben Adler).

### The wall with a minimum rating of 4

```sql
SELECT name, rating FROM testimonials WHERE status = 'published' AND consent = TRUE AND withdrawn_at IS NULL AND rating >= 4 ORDER BY CASE WHEN featured THEN 0 ELSE 1 END, submitted_at DESC;
```

On the seed data: 3 rows (Ana Moreno 5, Hugo Brandt 4, Ben Adler 5); Rosa Lind has no rating, so she appears only without a minimum.

### Pending queue, oldest first

```sql
SELECT t.name, t.company, CASE WHEN t.consent THEN 'Permission to publish' ELSE 'Private: no permission' END AS permission, COALESCE('Invitation from ' || p.name, 'Form') AS source FROM testimonials t LEFT JOIN invitations i ON i.id = t.invitation_id LEFT JOIN people p ON p.id = i.created_by_id WHERE t.status = 'pending' ORDER BY t.submitted_at;
```

On the seed data: 2 rows (Cy Patel, Acme, Permission to publish, Form; Lee Hart, Ridgeway, Private: no permission, Form).

### Invitations due a reminder, at T + 2 days

```sql
SELECT i.name, i.email, i.expires_at FROM invitations i WHERE i.status = 'open' AND i.reminded_at IS NULL AND i.created_at <= '2026-10-14 12:00:00' AND i.expires_at > '2026-10-17 12:00:00' ORDER BY i.created_at;
```

On the seed data, with now at 2026-10-17 12:00 UTC (72 hours after the invitation was created): 1 row (Nora Quinn, nora@lumenstudio.example, expires 2026-10-28 12:00 UTC).

### A testimonial's history

```sql
SELECT e.created_at, e.type, e.actor_type, COALESCE(p.name, '') AS actor, COALESCE(e.note, '') AS note FROM events e LEFT JOIN people p ON p.id = e.actor_id WHERE e.testimonial_id = 't-felix' ORDER BY e.created_at, e.id;
```

On the seed data: 2 rows (submitted by the customer; rejected by Jo Park with the note "Names a client and their spend. We can't publish that.").

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