Help desk ticketing system database schema

Nine tables. tickets carries the design: one assignee, six statuses, a stored first-response due time and a version number for stale-reply checks, with table CHECKs that keep a new ticket unassigned and a solved ticket owned. messages holds the thread and the email Message-IDs that threading and duplicate detection rely on, and notifications is the outbox every email passes through.

  • 9 tables, 8 indexes
  • Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite 0.6.1),
  • 19 seed rows from the blueprint
  • The blueprint's test build passed 24 of 24 acceptance checks

Copy the SQLDownload SQLDownload seed data

By Sam Claassen · From the Help Desk blueprint · MIT licensed · Markdown version

Help desk entity-relationship diagram

agentsidPK+ 4 more columnssettingsidPK+ 10 more columnsrequestersidPK+ 3 more columnsticketsidPKrequester_id→ requestersassignee_id→ agentsfollow_up_of→ tickets+ 12 more columnsmessagesidPKticket_id→ ticketsauthor_agent_id→ agents+ 4 more columnscanned_repliesidPKcreated_by→ agents+ 3 more columnseventsidPKticket_id→ ticketsactor_agent_id→ agents+ 3 more columnsnotificationsidPKticket_id→ tickets+ 11 more columnsform_submissionsidPK+ 2 more columnsagentsidPK+ 4 more columnssettingsidPK+ 10 more columnsrequestersidPK+ 3 more columnsticketsidPKrequester_id→ requestersassignee_id→ agentsfollow_up_of→ tickets+ 12 more columnsmessagesidPKticket_id→ ticketsauthor_agent_id→ agents+ 4 more columnscanned_repliesidPKcreated_by→ agents+ 3 more columnseventsidPKticket_id→ ticketsactor_agent_id→ agents+ 3 more columnsnotificationsidPKticket_id→ tickets+ 11 more columnsform_submissionsidPK+ 2 more columns
Each box is a table with its key columns. A line runs from a table up to a table it references, with the forked end on the side that has many rows; a dashed line is an optional reference.

Relationships

  • tickets.requester_id references requesters.id: each tickets row points to exactly one requesters row, and one requesters row can have many tickets rows pointing to it. On delete: cascade.
  • tickets.assignee_id references agents.id: each tickets row points to at most one agents row, and one agents row can have many tickets rows pointing to it.
  • tickets.follow_up_of references tickets.id: each tickets row points to at most one another tickets row, and one tickets row can have many tickets rows pointing to it.
  • messages.ticket_id references tickets.id: each messages row points to exactly one tickets row, and one tickets row can have many messages rows pointing to it. On delete: cascade.
  • messages.author_agent_id references agents.id: each messages row points to at most one agents row, and one agents row can have many messages rows pointing to it.
  • canned_replies.created_by references agents.id: each canned_replies row points to exactly one agents row, and one agents row can have many canned_replies rows pointing to it.
  • events.ticket_id references tickets.id: each events row points to at most one tickets row, and one tickets row can have many events rows pointing to it. On delete: cascade.
  • events.actor_agent_id references agents.id: each events row points to at most one agents row, and one agents row can have many events rows pointing to it.
  • notifications.ticket_id references tickets.id: each notifications row points to at most one tickets row, and one tickets row can have many notifications rows pointing to it. On delete: cascade.

Help desk tables

The schema has 9 tables. Every column below is read from the SQL file itself. Also described as: support ticket system database design, ticketing system tables, customer support database schema.

TableImplementsWhat a row is
agentsAgentA support team member who answers tickets; deactivated, never deleted.
settingsSettingsThe single row of company settings, first-response targets, auto-close days and the ticket number counter.
requestersRequesterA customer who wrote in by email or the web form.
ticketsTicketOne support request with its status, priority, assignee and first-response times.
messagesMessageOne entry in a ticket's thread: a requester email, a public reply or an internal note.
canned_repliesCannedReplyA saved reply an agent can insert and edit before sending.
eventsEventOne append-only history entry for a ticket action or a requester deletion.
notificationsNotificationOne outgoing email in the outbox, with its send status and attempts.
form_submissionsFormSubmissionOne public support form submission, kept to rate-limit by IP hash.

agents

A support team member who answers tickets. Agents are deactivated, never deleted.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
nameTEXTno
emailTEXTnoUniquestored lowercaseCheck: email = LOWER(email)
is_adminBOOLEANnoFALSE
activeBOOLEANnoTRUE
  • App rule (R6): deactivating an agent who still has tickets that are not solved or closed is refused.

settings

The single settings row for the one company and support address.

ColumnTypeNullDefaultKeyNotes
idINTEGERnoPrimary keyone row onlyCheck: id = 1
company_nameTEXTno
support_emailTEXTnothe address customers write to and replies come from
time_zoneTEXTno'America/New_York'IANA name; used for report weeks
target_urgent_minutesINTEGERno60Check: target_urgent_minutes BETWEEN 15 AND 10080
target_high_minutesINTEGERno240Check: target_high_minutes BETWEEN 15 AND 10080
target_normal_minutesINTEGERno480Check: target_normal_minutes BETWEEN 15 AND 10080
target_low_minutesINTEGERno1440Check: target_low_minutes BETWEEN 15 AND 10080
auto_close_daysINTEGERno4days after solved_atCheck: auto_close_days BETWEEN 1 AND 28
acknowledgement_templateTEXTyesplaceholders: {requester_first_name}, {ticket_number}, {subject}
last_ticket_numberINTEGERno1000counter for ticket numbers; deleting tickets never lowers it

requesters

A customer who wrote in by email or the web form. Requesters never sign in.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
emailTEXTnoUniquestored lowercaseCheck: email = LOWER(email)
nameTEXTyesoptionalCheck: LENGTH(name) <= 100
created_atTIMESTAMPno

tickets

One support request with one assignee and a status.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
numberINTEGERnoUniquetaken from settings.last_ticket_number + 1, never reusedCheck: number >= 1001
subjectTEXTnoCheck: LENGTH(subject) BETWEEN 1 AND 150
requester_idTEXTnoReferences requesters.id, on delete cascadeR14 removes a requester's tickets
channelTEXTnoCheck: channel IN ('email', 'web', 'agent')
statusTEXTnoCheck: status IN ('new', 'open', 'pending', 'on_hold', 'solved', 'closed')
priorityTEXTno'normal'Check: priority IN ('low', 'normal', 'high', 'urgent')
assignee_idTEXTyesReferences agents.idat most one assignee
follow_up_ofTEXTyesReferences tickets.idthe closed ticket this one follows up (R3)
created_atTIMESTAMPno
first_response_atTIMESTAMPyesfirst public reply by an agent
first_response_due_atTIMESTAMPno
solved_atTIMESTAMPyesset when solved, cleared when reopened, kept when closed
closed_atTIMESTAMPyes
updated_atTIMESTAMPno
versionINTEGERno1Check: version >= 1
  • Table check: status <> 'new' OR (assignee_id IS NULL AND first_response_at IS NULL)
  • Table check: status NOT IN ('solved', 'closed') OR assignee_id IS NOT NULL
  • Table check: (status IN ('solved', 'closed') AND solved_at IS NOT NULL) OR (status NOT IN ('solved', 'closed') AND solved_at IS NULL)
  • Table check: (status = 'closed' AND closed_at IS NOT NULL) OR (status <> 'closed' AND closed_at IS NULL)
  • Index tickets_status_idx on (status)
  • Index tickets_assignee_idx on (assignee_id)
  • Index tickets_requester_idx on (requester_id)
  • App rule (R6): assignee_id must point to an active agent.
  • App rule (R1, R2): a ticket never returns to new; agents can never set new or closed; only the job closes tickets.
  • App rule (R5): first_response_due_at = created_at + the target for the priority; recalculated on a priority change only before the first response.
  • App rule (R13): version goes up by 1 on every change.

messages

One entry in a ticket's thread: a requester email, a public reply or an internal note.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
ticket_idTEXTnoReferences tickets.id, on delete cascade
kindTEXTnoCheck: kind IN ('requester', 'public_reply', 'internal_note')
author_agent_idTEXTyesReferences agents.idset for public replies and notes, empty for requester messages
bodyTEXTnoplain text, shown as text, never as HTMLCheck: LENGTH(body) BETWEEN 1 AND 20000
email_message_idTEXTyesUniqueMessage-ID header of the email received or sent; used for threading (R11) and duplicates (R12)
created_atTIMESTAMPno
  • Table check: (kind = 'requester' AND author_agent_id IS NULL) OR (kind <> 'requester' AND author_agent_id IS NOT NULL)
  • Table check: kind <> 'internal_note' OR email_message_id IS NULL
  • Index messages_ticket_idx on (ticket_id, created_at)
  • App rule (R7): internal notes are never emailed or included in anything the requester receives.

canned_replies

A saved reply an agent can insert into the reply box. It never sends on its own (R9).

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
titleTEXTnoCheck: LENGTH(title) BETWEEN 1 AND 80
bodyTEXTnoplaceholders: {requester_first_name}, {ticket_number}, {agent_first_name}Check: LENGTH(body) BETWEEN 1 AND 5000
created_byTEXTnoReferences agents.id
updated_atTIMESTAMPno
  • Unique index canned_replies_title_uniq on (LOWER(title))

events

One append-only history entry. Never edited or deleted, except by R14.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
ticket_idTEXTyesReferences tickets.id, on delete cascadeempty for requester_deleted
actor_agent_idTEXTyesReferences agents.idempty for the requester and the system
typeTEXTnoCheck: type IN ('created', 'requester_replied', 'replied', 'note_added', 'assigned', 'status_changed', 'priority_changed', 'reopened', 'follow_up_created', 'closed', 'requester_deleted')
dataTEXTyesJSON text with from/to values; requester_deleted stores only the ticket count
created_atTIMESTAMPno
  • Index events_ticket_idx on (ticket_id, created_at)
  • App rule (R15): each action writes the events listed in section 6.

notifications

One outgoing email in the outbox. Written first, then sent.

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
kindTEXTnoCheck: kind IN ('acknowledgement', 'public_reply', 'assignment')
to_emailTEXTno
ticket_idTEXTyesReferences tickets.id, on delete cascadeR14 removes the outbox rows of deleted tickets
subjectTEXTno
bodyTEXTno
message_id_headerTEXTnoa new Message-ID for every email
in_reply_to_headerTEXTyesnewest Message-ID among the requester's emails, the acknowledgement and earlier replies (R8)
statusTEXTno'pending'logged = no email provider configuredCheck: status IN ('pending', 'sent', 'logged', 'failed')
errorTEXTyes
attemptsINTEGERno06 attempts in all (section 10)Check: attempts BETWEEN 0 AND 6
created_atTIMESTAMPno
sent_atTIMESTAMPyes
  • Index notifications_status_idx on (status)

form_submissions

One public support form submission, kept for the rate limit (5 per IP hash per hour).

ColumnTypeNullDefaultKeyNotes
idTEXTnoPrimary key
ip_hashTEXTnoSHA-256 of the IP address with a server secret; the IP itself is never stored
created_atTIMESTAMPno
  • Index form_submissions_ip_idx on (ip_hash, created_at)

The SQL

The whole schema in one file. It runs top to bottom, unmodified, on SQLite and PostgreSQL. Download help-desk.sql or copy it from here.

help-desk.sql
-- Help Desk database schema
-- Source: https://personalsoftwarefactory.com/blueprints/help-desk (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 support team member who answers tickets. Agents are deactivated, never deleted.
-- App rule (R6): deactivating an agent who still has tickets that are not solved or closed is refused.
CREATE TABLE agents (
  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 for the one company and support address.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY CHECK (id = 1), -- one row only
  company_name TEXT NOT NULL,
  support_email TEXT NOT NULL, -- the address customers write to and replies come from
  time_zone TEXT NOT NULL DEFAULT 'America/New_York', -- IANA name; used for report weeks
  target_urgent_minutes INTEGER NOT NULL DEFAULT 60 CHECK (target_urgent_minutes BETWEEN 15 AND 10080),
  target_high_minutes INTEGER NOT NULL DEFAULT 240 CHECK (target_high_minutes BETWEEN 15 AND 10080),
  target_normal_minutes INTEGER NOT NULL DEFAULT 480 CHECK (target_normal_minutes BETWEEN 15 AND 10080),
  target_low_minutes INTEGER NOT NULL DEFAULT 1440 CHECK (target_low_minutes BETWEEN 15 AND 10080),
  auto_close_days INTEGER NOT NULL DEFAULT 4 CHECK (auto_close_days BETWEEN 1 AND 28), -- days after solved_at
  acknowledgement_template TEXT, -- placeholders: {requester_first_name}, {ticket_number}, {subject}
  last_ticket_number INTEGER NOT NULL DEFAULT 1000 -- counter for ticket numbers; deleting tickets never lowers it
);

-- A customer who wrote in by email or the web form. Requesters never sign in.
CREATE TABLE requesters (
  id TEXT PRIMARY KEY,
  email TEXT NOT NULL UNIQUE CHECK (email = LOWER(email)), -- stored lowercase
  name TEXT CHECK (LENGTH(name) <= 100), -- optional
  created_at TIMESTAMP NOT NULL
);

-- One support request with one assignee and a status.
-- App rule (R6): assignee_id must point to an active agent.
-- App rule (R1, R2): a ticket never returns to new; agents can never set new or closed; only the job closes tickets.
-- App rule (R5): first_response_due_at = created_at + the target for the priority; recalculated on a priority change only before the first response.
-- App rule (R13): version goes up by 1 on every change.
CREATE TABLE tickets (
  id TEXT PRIMARY KEY,
  number INTEGER NOT NULL UNIQUE CHECK (number >= 1001), -- taken from settings.last_ticket_number + 1, never reused
  subject TEXT NOT NULL CHECK (LENGTH(subject) BETWEEN 1 AND 150),
  requester_id TEXT NOT NULL REFERENCES requesters(id) ON DELETE CASCADE, -- R14 removes a requester's tickets
  channel TEXT NOT NULL CHECK (channel IN ('email', 'web', 'agent')),
  status TEXT NOT NULL CHECK (status IN ('new', 'open', 'pending', 'on_hold', 'solved', 'closed')),
  priority TEXT NOT NULL DEFAULT 'normal' CHECK (priority IN ('low', 'normal', 'high', 'urgent')),
  assignee_id TEXT REFERENCES agents(id), -- at most one assignee
  follow_up_of TEXT REFERENCES tickets(id), -- the closed ticket this one follows up (R3)
  created_at TIMESTAMP NOT NULL,
  first_response_at TIMESTAMP, -- first public reply by an agent
  first_response_due_at TIMESTAMP NOT NULL,
  solved_at TIMESTAMP, -- set when solved, cleared when reopened, kept when closed
  closed_at TIMESTAMP,
  updated_at TIMESTAMP NOT NULL,
  version INTEGER NOT NULL DEFAULT 1 CHECK (version >= 1),
  CHECK (status <> 'new' OR (assignee_id IS NULL AND first_response_at IS NULL)), -- R1: assignment or a first reply makes it open
  CHECK (status NOT IN ('solved', 'closed') OR assignee_id IS NOT NULL), -- R4: solving needs an owner
  CHECK ((status IN ('solved', 'closed') AND solved_at IS NOT NULL) OR (status NOT IN ('solved', 'closed') AND solved_at IS NULL)),
  CHECK ((status = 'closed' AND closed_at IS NOT NULL) OR (status <> 'closed' AND closed_at IS NULL))
);
CREATE INDEX tickets_status_idx ON tickets (status);
CREATE INDEX tickets_assignee_idx ON tickets (assignee_id);
CREATE INDEX tickets_requester_idx ON tickets (requester_id);

-- One entry in a ticket's thread: a requester email, a public reply or an internal note.
-- App rule (R7): internal notes are never emailed or included in anything the requester receives.
CREATE TABLE messages (
  id TEXT PRIMARY KEY,
  ticket_id TEXT NOT NULL REFERENCES tickets(id) ON DELETE CASCADE,
  kind TEXT NOT NULL CHECK (kind IN ('requester', 'public_reply', 'internal_note')),
  author_agent_id TEXT REFERENCES agents(id), -- set for public replies and notes, empty for requester messages
  body TEXT NOT NULL CHECK (LENGTH(body) BETWEEN 1 AND 20000), -- plain text, shown as text, never as HTML
  email_message_id TEXT UNIQUE, -- Message-ID header of the email received or sent; used for threading (R11) and duplicates (R12)
  created_at TIMESTAMP NOT NULL,
  CHECK ((kind = 'requester' AND author_agent_id IS NULL) OR (kind <> 'requester' AND author_agent_id IS NOT NULL)),
  CHECK (kind <> 'internal_note' OR email_message_id IS NULL) -- internal notes are not emails
);
CREATE INDEX messages_ticket_idx ON messages (ticket_id, created_at);

-- A saved reply an agent can insert into the reply box. It never sends on its own (R9).
CREATE TABLE canned_replies (
  id TEXT PRIMARY KEY,
  title TEXT NOT NULL CHECK (LENGTH(title) BETWEEN 1 AND 80),
  body TEXT NOT NULL CHECK (LENGTH(body) BETWEEN 1 AND 5000), -- placeholders: {requester_first_name}, {ticket_number}, {agent_first_name}
  created_by TEXT NOT NULL REFERENCES agents(id),
  updated_at TIMESTAMP NOT NULL
);
CREATE UNIQUE INDEX canned_replies_title_uniq ON canned_replies (LOWER(title)); -- unique ignoring case

-- One append-only history entry. Never edited or deleted, except by R14.
-- App rule (R15): each action writes the events listed in section 6.
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  ticket_id TEXT REFERENCES tickets(id) ON DELETE CASCADE, -- empty for requester_deleted
  actor_agent_id TEXT REFERENCES agents(id), -- empty for the requester and the system
  type TEXT NOT NULL CHECK (type IN ('created', 'requester_replied', 'replied', 'note_added', 'assigned', 'status_changed', 'priority_changed', 'reopened', 'follow_up_created', 'closed', 'requester_deleted')),
  data TEXT, -- JSON text with from/to values; requester_deleted stores only the ticket count
  created_at TIMESTAMP NOT NULL
);
CREATE INDEX events_ticket_idx ON events (ticket_id, created_at);

-- One outgoing email in the outbox. Written first, then sent.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  kind TEXT NOT NULL CHECK (kind IN ('acknowledgement', 'public_reply', 'assignment')),
  to_email TEXT NOT NULL,
  ticket_id TEXT REFERENCES tickets(id) ON DELETE CASCADE, -- R14 removes the outbox rows of deleted tickets
  subject TEXT NOT NULL,
  body TEXT NOT NULL,
  message_id_header TEXT NOT NULL, -- a new Message-ID for every email
  in_reply_to_header TEXT, -- newest Message-ID among the requester's emails, the acknowledgement and earlier replies (R8)
  status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'sent', 'logged', 'failed')), -- logged = no email provider configured
  error TEXT,
  attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts BETWEEN 0 AND 6), -- 6 attempts in all (section 10)
  created_at TIMESTAMP NOT NULL,
  sent_at TIMESTAMP
);
CREATE INDEX notifications_status_idx ON notifications (status);

-- One public support form submission, kept for the rate limit (5 per IP hash per hour).
CREATE TABLE form_submissions (
  id TEXT PRIMARY KEY,
  ip_hash TEXT NOT NULL, -- SHA-256 of the IP address with a server secret; the IP itself is never stored
  created_at TIMESTAMP NOT NULL
);
CREATE INDEX form_submissions_ip_idx ON form_submissions (ip_hash, created_at);

Seed data

Loads the settings row, the 3 agents, the 7 requesters and the 8 tickets from section 14, with T fixed at 2026-12-04 12:00:00 UTC. Left out: the messages, because the spec leaves their text to the builder and gives no time for Ben's internal note; the 2 canned replies, because the spec gives no author or time and only sketches the second one's text; and events, which the spec does not seed. Tickets load at version 1, and updated_at is the latest time the spec gives for each ticket.

Download help-desk-seed.sql (19 rows). It loads with foreign keys enforced on both engines.

Load it

SQLite, into a new file:

sqlite3
curl -s https://personalsoftwarefactory.com/schemas/help-desk.sql https://personalsoftwarefactory.com/schemas/help-desk-seed.sql | sqlite3 help_desk.db

PostgreSQL, into a new database:

psql
createdb help_desk && curl -s https://personalsoftwarefactory.com/schemas/help-desk.sql https://personalsoftwarefactory.com/schemas/help-desk-seed.sql | psql -v ON_ERROR_STOP=1 help_desk

SQLite only enforces foreign keys when the connection asks for it: run PRAGMA foreign_keys = ON; when your app opens the database.

Design decisions

Ticket numbers come from a stored counter

From the build test · field report

Section 5 says numbers run from 1001 and are taken from a stored counter, last_ticket_number, that deleting tickets never lowers. It lives on the one settings row, and tickets.number is UNIQUE with a floor of 1001. Taking MAX(number) + 1 instead would reuse a number after R14 deletes the newest tickets, and an old reply with that number in its subject could thread into a stranger's ticket. The build test found section 5 had nowhere to store this counter; it was added.

The first-response due time is stored, not computed

R5 sets first_response_due_at at creation from the priority's target and recalculates it only while there is no first response. Storing it lets the queue sort waiting tickets by due time with a plain ORDER BY, and keeps the deadline fixed once an agent has replied, even if the priority or the settings change later.

Status rules that fit one row are CHECK constraints

R1 means a new ticket has no assignee and no first response; R4 means a solved or closed ticket has an assignee; section 6 means solved_at is set exactly when the ticket is solved or closed and closed_at exactly when it is closed. The transitions themselves (never back to new, only the job closes) stay in the app, because they compare a row with its previous state.

Message-IDs are unique and live on messages

From the build test · field report

R11 threads an inbound email by its In-Reply-To or References headers, and R12 ignores an email whose Message-ID was already received; a UNIQUE email_message_id makes the duplicate check a constraint, not a race. The build test found that "the last email in the thread" could pick an internal note for In-Reply-To; R8 now names only emails, and a CHECK here keeps a note's Message-ID empty.

Deleting a requester cascades

R14 removes a requester's tickets, messages and outbox rows and keeps one requester_deleted event with no ticket and no personal data. ON DELETE CASCADE from requesters to tickets, and from tickets to messages, events and notifications, does that in one DELETE. The kept event has an empty ticket_id, so the cascade cannot reach it.

A version column for stale replies

R13 stops a reply when the ticket changed since the agent opened it. tickets.version starts at 1 and goes up on every change; the app sends the version it showed and refuses the write when it no longer matches. Without it, two agents answer the same customer, which is the problem section 1 starts from.

Rate limiting and retries have their own columns

From the build test · field report

The build test found section 5 had nowhere to store the support form's rate limit, the ticket counter or email retry attempts. form_submissions keeps only a salted IP hash and a time, and notifications.attempts is capped at 6 by a CHECK, the total section 10 allows.

Example queries

The queries behind the tool's main screens. Each returned the same rows on both engines against the seed data.

Unassigned queue, waiting tickets first

SQL
SELECT t.number, t.subject, r.email AS requester, t.priority, CASE WHEN t.first_response_at IS NOT NULL THEN 'responded' WHEN t.first_response_due_at < '2026-12-04 12:00:00' THEN 'overdue' ELSE 'due' END AS first_response_state, t.first_response_due_at FROM tickets t JOIN requesters r ON r.id = t.requester_id WHERE t.status IN ('new', 'open') AND t.assignee_id IS NULL ORDER BY CASE WHEN t.first_response_at IS NULL THEN 0 ELSE 1 END, CASE WHEN t.first_response_at IS NULL THEN t.first_response_due_at END, t.updated_at;

On the seed data at T: 2 rows, #1002 (overdue) above #1001 (due at 13:00).

Queue counts for the sidebar

SQL
SELECT SUM(CASE WHEN status IN ('new', 'open') AND assignee_id IS NULL THEN 1 ELSE 0 END) AS unassigned, SUM(CASE WHEN assignee_id = 'agent_jo' AND status NOT IN ('solved', 'closed') THEN 1 ELSE 0 END) AS mine_jo, SUM(CASE WHEN status IN ('new', 'open', 'on_hold') THEN 1 ELSE 0 END) AS all_open, SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) AS pending, SUM(CASE WHEN status IN ('solved', 'closed') AND solved_at >= '2026-11-04 12:00:00' THEN 1 ELSE 0 END) AS solved_30_days FROM tickets;

On the seed data: 1 row, Unassigned 2, Mine for Jo Park 2, All open 4, Pending 1, Solved 3.

A requester's ticket history

SQL
SELECT t.number, t.subject, t.status, t.created_at, f.number AS follow_up_of FROM tickets t JOIN requesters r ON r.id = t.requester_id LEFT JOIN tickets f ON f.id = t.follow_up_of WHERE r.email = 'max@bluebird.example' ORDER BY t.created_at DESC;

On the seed data: 2 rows for Max Ford, #1001 (new) and #1008 (closed).

Tickets the scheduled job closes

SQL
SELECT t.number, t.subject, t.solved_at FROM tickets t WHERE t.status = 'solved' AND t.solved_at <= '2026-11-30 12:00:00' ORDER BY t.solved_at;

On the seed data, with the cutoff at T minus auto_close_days (4): 1 row, #1007 solved 2026-11-29; #1006 stays solved.

One week of the report

SQL
SELECT COUNT(*) AS created, SUM(CASE WHEN first_response_at IS NOT NULL THEN 1 ELSE 0 END) AS with_first_response, SUM(CASE WHEN first_response_at IS NOT NULL AND first_response_at <= first_response_due_at THEN 1 ELSE 0 END) AS within_target, (SELECT COUNT(*) FROM tickets s WHERE s.solved_at >= '2026-11-30 05:00:00' AND s.solved_at < '2026-12-07 05:00:00') AS solved FROM tickets WHERE created_at >= '2026-11-30 05:00:00' AND created_at < '2026-12-07 05:00:00';

On the seed data, for the week of Monday 2026-11-30 in America/New_York: 1 row, 6 created, 4 with a first response, 4 within target, 1 solved.

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 comes from

Tables are the easy half. This schema is section 5 of the Help Desk blueprint, a free spec that also has the business rules, the screens, 4 phased build prompts and 24 acceptance checks for building the whole tool with an AI app builder. We built it from those prompts and the result passed 24 of 24 acceptance checks in a browser.

Follow new blueprints

Every new blueprint and build test appears in the feed and in the public GitHub repository. No account, no email list.