# Applicant tracking system database schema

Source: https://personalsoftwarefactory.com/schemas/hiring-pipeline
Updated: 2026-12-05

> Thirteen tables. Applications carry the design: one row per candidate per role, with a stage from a fixed list, the stage it closed from, a reject reason that exists only while rejected, consent from the careers form and a private withdraw token. Interviews hold one scorecard per interviewer, and ratings sit in their own table keyed by scorecard and role attribute, so the app can show feedback without ever turning it into a score.

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

Files: [hiring-pipeline.sql](https://personalsoftwarefactory.com/schemas/hiring-pipeline.sql) · [hiring-pipeline-seed.sql](https://personalsoftwarefactory.com/schemas/hiring-pipeline-seed.sql) · [the Hiring Pipeline blueprint](https://personalsoftwarefactory.com/blueprints/hiring-pipeline)

## Relationships

- roles.hiring_manager_id references people.id: each roles row points to at most one people row, and one people row can have many roles rows pointing to it.
- role_attributes.role_id references roles.id: each role_attributes row points to exactly one roles row, and one roles row can have many role_attributes rows pointing to it.
- applications.candidate_id references candidates.id: each applications row points to exactly one candidates row, and one candidates row can have many applications rows pointing to it.
- applications.role_id references roles.id: each applications row points to exactly one roles row, and one roles row can have many applications rows pointing to it.
- interviews.application_id references applications.id: each interviews row points to exactly one applications row, and one applications row can have many interviews rows pointing to it.
- interviews.created_by references people.id: each interviews row points to at most one people row, and one people row can have many interviews rows pointing to it.
- scorecards.interview_id references interviews.id: each scorecards row points to exactly one interviews row, and one interviews row can have many scorecards rows pointing to it.
- scorecards.interviewer_id references people.id: each scorecards row points to exactly one people row, and one people row can have many scorecards rows pointing to it.
- attribute_ratings.scorecard_id references scorecards.id: each attribute_ratings row points to exactly one scorecards row, and one scorecards row can have many attribute_ratings rows pointing to it.
- attribute_ratings.attribute_id references role_attributes.id: each attribute_ratings row points to exactly one role_attributes row, and one role_attributes row can have many attribute_ratings rows pointing to it.
- notes.application_id references applications.id: each notes row points to exactly one applications row, and one applications row can have many notes rows pointing to it.
- notes.author_id references people.id: each notes row points to exactly one people row, and one people row can have many notes rows pointing to it.
- events.application_id references applications.id: each events row points to at most one applications row, and one applications row can have many events 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.application_id references applications.id: each notifications row points to at most one applications row, and one applications row can have many notifications rows pointing to it.

## Tables

Also described as: recruitment database design, hiring pipeline database tables, ATS data model.

### people

A member of the hiring team who can sign in. Implements: Person.

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

- App rule (R17): deactivating a hiring manager of an open or paused role, or someone with pending scorecards, is refused; at least one active admin remains.

### settings

The single row with the company name, privacy notice and version, retention days and rejection template. Implements: Settings.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | INTEGER | no |  | Primary key | one row only Check: `id = 1` |
| `company_name` | TEXT | no |  |  | Check: `LENGTH(company_name) BETWEEN 1 AND 60` |
| `time_zone` | TEXT | no | `'America/New_York'` |  | IANA name; dates and the 08:00 digest use it |
| `careers_intro` | TEXT | yes |  |  | optional, top of the careers page Check: `LENGTH(careers_intro) <= 1000` |
| `privacy_notice` | TEXT | no |  |  | the text candidates accept Check: `LENGTH(privacy_notice) BETWEEN 1 AND 2000` |
| `privacy_version` | INTEGER | no | `1` |  | Check: `privacy_version >= 1` |
| `retention_days` | INTEGER | no | `180` |  | Check: `retention_days BETWEEN 30 AND 730` |
| `rejection_template` | TEXT | no |  |  | may use {candidate_first_name}, {role_title}, {company_name} Check: `LENGTH(rejection_template) BETWEEN 1 AND 2000` |
| `last_digest_at` | TIMESTAMP | yes |  |  | written only by the scheduled job |

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

### roles

A job with its hiring manager, location, description and status. Implements: Role.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `title` | TEXT | no |  |  | Check: `LENGTH(title) BETWEEN 1 AND 100` |
| `department` | TEXT | yes |  |  | optional Check: `LENGTH(department) <= 60` |
| `location` | TEXT | no |  |  | for example Remote (US) Check: `LENGTH(location) BETWEEN 1 AND 80` |
| `description` | TEXT | no |  |  | Markdown Check: `LENGTH(description) BETWEEN 20 AND 5000` |
| `hiring_manager_id` | TEXT | yes |  | References people.id | must be an active person; required to open the role |
| `status` | TEXT | no | `'paused'` |  | Check: `status IN ('open', 'paused', 'closed')` |
| `opened_at` | TIMESTAMP | yes |  |  | empty until the role is first opened |
| `closed_at` | TIMESTAMP | yes |  |  |  |

- Table check: `status <> 'open' OR (hiring_manager_id IS NOT NULL AND opened_at IS NOT NULL)`
- Unique index `roles_title_uniq` on (LOWER(title)) where `status <> 'closed'`
- App rule (R4): a role needs 3 to 6 attributes to be opened; closing a role rejects its open applications in the same action.

### role_attributes

One scorecard criterion of a role, in display order. Implements: RoleAttribute.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `role_id` | TEXT | no |  | References roles.id |  |
| `name` | TEXT | no |  |  | Check: `LENGTH(name) BETWEEN 2 AND 60` |
| `position` | INTEGER | no |  |  | display order on the scorecard |

- Unique index `role_attributes_name_uniq` on (role_id, LOWER(name))
- App rule (section 5): an attribute that has ratings can be renamed or reordered but not removed.

### candidates

A person who applied or was added, matched by email. Implements: Candidate.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | Check: `LENGTH(name) BETWEEN 1 AND 100` |
| `email` | TEXT | yes |  |  | stored lowercase; cleared only by anonymization Check: `LENGTH(email) <= 254 AND email = LOWER(email)` |
| `phone` | TEXT | yes |  |  | Check: `LENGTH(phone) <= 30` |
| `link` | TEXT | yes |  |  | CV, LinkedIn or portfolio Check: `LENGTH(link) <= 2000 AND link LIKE 'https://%'` |
| `anonymized_at` | TIMESTAMP | yes |  |  |  |

- Table check: `anonymized_at IS NOT NULL OR email IS NOT NULL`
- Unique index `candidates_email_uniq` on (email) where `anonymized_at IS NULL`
- App rule (R14): when no application is open, hired or inside the retention window, name becomes Anonymized candidate and email, phone and link are cleared.

### applications

One candidate for one role, with its stage, source, consent and close details. Implements: Application.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `candidate_id` | TEXT | no |  | References candidates.id |  |
| `role_id` | TEXT | no |  | References roles.id |  |
| `source` | TEXT | no |  |  | Check: `source IN ('careers_page', 'referral', 'sourced', 'agency', 'other')` |
| `source_detail` | TEXT | yes |  |  | for example the referrer name Check: `LENGTH(source_detail) <= 100` |
| `answer` | TEXT | yes |  |  | Why this role? Required on the careers form, optional when the team adds a candidate Check: `LENGTH(answer) BETWEEN 1 AND 2000` |
| `consent_at` | TIMESTAMP | yes |  |  | from the privacy checkbox; NULL when the team added the candidate |
| `consent_version` | INTEGER | yes |  |  | the privacy_version accepted |
| `stage` | TEXT | no | `'applied'` |  | Check: `stage IN ('applied', 'screen', 'interview', 'offer', 'hired', 'rejected', 'withdrawn')` |
| `stage_before_close` | TEXT | yes |  |  | the stage when rejected or withdrawn Check: `stage_before_close IN ('applied', 'screen', 'interview', 'offer')` |
| `reject_reason` | TEXT | yes |  |  | Check: `reject_reason IN ('requirements', 'chose_another', 'role_closed', 'no_response', 'other')` |
| `close_note` | TEXT | yes |  |  | Check: `LENGTH(close_note) <= 500` |
| `applied_at` | TIMESTAMP | no |  |  |  |
| `stage_changed_at` | TIMESTAMP | no |  |  |  |
| `closed_at` | TIMESTAMP | yes |  |  | set by hire, reject and withdraw |
| `withdraw_token` | TEXT | no |  | Unique | at least 128 random bits, URL-safe (R13) |
| `anonymized_at` | TIMESTAMP | yes |  |  |  |

- Unique together: `candidate_id`, `role_id`
- Table check: `(consent_at IS NULL AND consent_version IS NULL) OR (consent_at IS NOT NULL AND consent_version IS NOT NULL)`
- Table check: `(stage IN ('hired', 'rejected', 'withdrawn') AND closed_at IS NOT NULL) OR (stage IN ('applied', 'screen', 'interview', 'offer') AND closed_at IS NULL)`
- Table check: `stage NOT IN ('rejected', 'withdrawn') OR stage_before_close IS NOT NULL`
- Table check: `(stage = 'rejected' AND reject_reason IS NOT NULL) OR (stage <> 'rejected' AND reject_reason IS NULL)`
- App rule (R6): advance and move back change the stage by exactly one step.
- App rule (R7): Interview to Offer needs a submitted scorecard and no pending ones on interviews that are not cancelled.
- App rule (R14): anonymization clears answer and close_note.

### interviews

A scheduled screen or interview on an application. Implements: Interview.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `application_id` | TEXT | no |  | References applications.id |  |
| `kind` | TEXT | no |  |  | Check: `kind IN ('screen', 'interview')` |
| `starts_at` | TIMESTAMP | no |  |  |  |
| `duration_minutes` | INTEGER | yes |  |  | Check: `duration_minutes BETWEEN 15 AND 240` |
| `location` | TEXT | yes |  |  | a room, a phone number or a video link; required when scheduling Check: `LENGTH(location) <= 200` |
| `created_by` | TEXT | yes |  | References people.id | who scheduled it |
| `created_at` | TIMESTAMP | no |  |  |  |
| `cancelled_at` | TIMESTAMP | yes |  |  |  |

- App rule (section 7): 1 to 4 active interviewers, one pending scorecard each.
- App rule (R14): anonymization clears location.

### scorecards

One interviewer feedback form for one interview. Implements: Scorecard.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `interview_id` | TEXT | no |  | References interviews.id |  |
| `interviewer_id` | TEXT | no |  | References people.id |  |
| `status` | TEXT | no | `'pending'` |  | Check: `status IN ('pending', 'submitted', 'cancelled')` |
| `takeaways` | TEXT | yes |  |  | Check: `LENGTH(takeaways) BETWEEN 20 AND 3000` |
| `recommendation` | TEXT | yes |  |  | no default; no_decision is an explicit choice Check: `recommendation IN ('definitely_not', 'no', 'yes', 'strong_yes', 'no_decision')` |
| `submitted_at` | TIMESTAMP | yes |  |  |  |
| `reminded_at` | TIMESTAMP | yes |  |  | set by the job 24 hours after the interview started |

- Unique together: `interview_id`, `interviewer_id`
- Table check: `(status = 'submitted' AND recommendation IS NOT NULL AND submitted_at IS NOT NULL) OR (status <> 'submitted' AND submitted_at IS NULL)`
- App rule (R10): only the assigned interviewer submits, once, after starts_at, with at least one rating and takeaways of 20 or more characters.
- App rule (R14): anonymization deletes takeaways.

### attribute_ratings

One 1 to 4 rating, or Not assessed, for one attribute on a scorecard. Implements: AttributeRating.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `scorecard_id` | TEXT | no |  | Primary key (part); References scorecards.id |  |
| `attribute_id` | TEXT | no |  | Primary key (part); References role_attributes.id |  |
| `rating` | INTEGER | yes |  |  | NULL means Not assessed; 1 Weak, 2 Mixed, 3 Good, 4 Strong Check: `rating BETWEEN 1 AND 4` |

### notes

An internal comment on an application, hidden from interviewers. Implements: Note.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `application_id` | TEXT | no |  | References applications.id |  |
| `author_id` | TEXT | no |  | References people.id |  |
| `text` | TEXT | no |  |  | Check: `LENGTH(text) BETWEEN 1 AND 2000` |
| `created_at` | TIMESTAMP | no |  |  |  |

### events

One line of the append-only activity log, with no candidate personal data. Implements: Event.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `application_id` | TEXT | yes |  | References applications.id | NULL for candidate_deleted, role and settings events |
| `actor_id` | TEXT | yes |  | References people.id | NULL for the candidate and the system |
| `type` | TEXT | no |  |  | Check: `type IN ('applied', 'added', 'stage_changed', 'rejected', 'withdrawn', 'reopened', 'hired', 'interview_scheduled', 'interview_cancelled', 'scorecard_submitted', 'note_added', 'anonymized', 'candidate_deleted', 'role_created', 'role_changed', 'settings_changed')` |
| `data` | TEXT | yes |  |  | JSON text: from/to stage, reason, counts |
| `created_at` | TIMESTAMP | no |  |  |  |

- App rule (R18): events are never edited, and only removed by Delete now (R16).

### notifications

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

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `kind` | TEXT | no |  |  | the trigger from section 10; the spec gives no fixed list of values |
| `to_email` | TEXT | no |  |  |  |
| `person_id` | TEXT | yes |  | References people.id | NULL for candidates |
| `application_id` | TEXT | yes |  | References applications.id |  |
| `subject` | TEXT | no |  |  |  |
| `body` | TEXT | no |  |  | plain text |
| `status` | TEXT | no | `'pending'` |  | Check: `status IN ('pending', 'sent', 'logged', 'failed')` |
| `error` | TEXT | yes |  |  |  |
| `attempts` | INTEGER | no | `0` |  | each send attempt adds 1; retries stop at 5 Check: `attempts >= 0` |
| `created_at` | TIMESTAMP | no |  |  |  |
| `sent_at` | TIMESTAMP | yes |  |  |  |

### apply_attempts

One accepted careers-form submission, keyed by a hash of the IP, for the rate limit. Implements: ApplyAttempt.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key | row id; the spec lists only ip_hash and created_at |
| `ip_hash` | TEXT | no |  |  | HMAC of the IP address with a server secret; the IP itself is never stored |
| `created_at` | TIMESTAMP | no |  |  |  |

- Index `apply_attempts_ip_idx` on (ip_hash, created_at)

## The SQL

```sql
-- Hiring Pipeline database schema
-- Source: https://personalsoftwarefactory.com/blueprints/hiring-pipeline (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 member of the hiring team who can sign in. People are deactivated, never deleted.
-- App rule (R17): deactivating a hiring manager of an open or paused role, or someone with pending scorecards, is refused; at least one active admin remains.
CREATE TABLE people (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (LENGTH(name) >= 1),
  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 company.
-- App rule (R15): changing privacy_notice adds 1 to privacy_version and writes a settings_changed event.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY CHECK (id = 1), -- one row only
  company_name TEXT NOT NULL CHECK (LENGTH(company_name) BETWEEN 1 AND 60),
  time_zone TEXT NOT NULL DEFAULT 'America/New_York', -- IANA name; dates and the 08:00 digest use it
  careers_intro TEXT CHECK (LENGTH(careers_intro) <= 1000), -- optional, top of the careers page
  privacy_notice TEXT NOT NULL CHECK (LENGTH(privacy_notice) BETWEEN 1 AND 2000), -- the text candidates accept
  privacy_version INTEGER NOT NULL DEFAULT 1 CHECK (privacy_version >= 1),
  retention_days INTEGER NOT NULL DEFAULT 180 CHECK (retention_days BETWEEN 30 AND 730),
  rejection_template TEXT NOT NULL CHECK (LENGTH(rejection_template) BETWEEN 1 AND 2000), -- may use {candidate_first_name}, {role_title}, {company_name}
  last_digest_at TIMESTAMP -- written only by the scheduled job
);

-- A job the team is hiring for.
-- App rule (R4): a role needs 3 to 6 attributes to be opened; closing a role rejects its open applications in the same action.
CREATE TABLE roles (
  id TEXT PRIMARY KEY,
  title TEXT NOT NULL CHECK (LENGTH(title) BETWEEN 1 AND 100),
  department TEXT CHECK (LENGTH(department) <= 60), -- optional
  location TEXT NOT NULL CHECK (LENGTH(location) BETWEEN 1 AND 80), -- for example Remote (US)
  description TEXT NOT NULL CHECK (LENGTH(description) BETWEEN 20 AND 5000), -- Markdown
  hiring_manager_id TEXT REFERENCES people(id), -- must be an active person; required to open the role
  status TEXT NOT NULL DEFAULT 'paused' CHECK (status IN ('open', 'paused', 'closed')),
  opened_at TIMESTAMP, -- empty until the role is first opened
  closed_at TIMESTAMP,
  CHECK (status <> 'open' OR (hiring_manager_id IS NOT NULL AND opened_at IS NOT NULL))
);
CREATE UNIQUE INDEX roles_title_uniq ON roles (LOWER(title)) WHERE status <> 'closed'; -- unique ignoring case among roles that are not closed

-- One scorecard criterion of a role.
-- App rule (section 5): an attribute that has ratings can be renamed or reordered but not removed.
CREATE TABLE role_attributes (
  id TEXT PRIMARY KEY,
  role_id TEXT NOT NULL REFERENCES roles(id),
  name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 2 AND 60),
  position INTEGER NOT NULL -- display order on the scorecard
);
CREATE UNIQUE INDEX role_attributes_name_uniq ON role_attributes (role_id, LOWER(name)); -- unique per role ignoring case

-- A person who applied or was added by the team.
-- App rule (R14): when no application is open, hired or inside the retention window, name becomes Anonymized candidate and email, phone and link are cleared.
CREATE TABLE candidates (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 1 AND 100),
  email TEXT CHECK (LENGTH(email) <= 254 AND email = LOWER(email)), -- stored lowercase; cleared only by anonymization
  phone TEXT CHECK (LENGTH(phone) <= 30),
  link TEXT CHECK (LENGTH(link) <= 2000 AND link LIKE 'https://%'), -- CV, LinkedIn or portfolio
  anonymized_at TIMESTAMP,
  CHECK (anonymized_at IS NOT NULL OR email IS NOT NULL)
);
CREATE UNIQUE INDEX candidates_email_uniq ON candidates (email) WHERE anonymized_at IS NULL; -- unique among candidates that are not anonymized

-- One candidate for one role, moving through the stages.
-- App rule (R6): advance and move back change the stage by exactly one step.
-- App rule (R7): Interview to Offer needs a submitted scorecard and no pending ones on interviews that are not cancelled.
-- App rule (R14): anonymization clears answer and close_note.
CREATE TABLE applications (
  id TEXT PRIMARY KEY,
  candidate_id TEXT NOT NULL REFERENCES candidates(id),
  role_id TEXT NOT NULL REFERENCES roles(id),
  source TEXT NOT NULL CHECK (source IN ('careers_page', 'referral', 'sourced', 'agency', 'other')),
  source_detail TEXT CHECK (LENGTH(source_detail) <= 100), -- for example the referrer name
  answer TEXT CHECK (LENGTH(answer) BETWEEN 1 AND 2000), -- Why this role? Required on the careers form, optional when the team adds a candidate
  consent_at TIMESTAMP, -- from the privacy checkbox; NULL when the team added the candidate
  consent_version INTEGER, -- the privacy_version accepted
  stage TEXT NOT NULL DEFAULT 'applied' CHECK (stage IN ('applied', 'screen', 'interview', 'offer', 'hired', 'rejected', 'withdrawn')),
  stage_before_close TEXT CHECK (stage_before_close IN ('applied', 'screen', 'interview', 'offer')), -- the stage when rejected or withdrawn
  reject_reason TEXT CHECK (reject_reason IN ('requirements', 'chose_another', 'role_closed', 'no_response', 'other')),
  close_note TEXT CHECK (LENGTH(close_note) <= 500),
  applied_at TIMESTAMP NOT NULL,
  stage_changed_at TIMESTAMP NOT NULL,
  closed_at TIMESTAMP, -- set by hire, reject and withdraw
  withdraw_token TEXT NOT NULL UNIQUE, -- at least 128 random bits, URL-safe (R13)
  anonymized_at TIMESTAMP,
  UNIQUE (candidate_id, role_id),
  CHECK ((consent_at IS NULL AND consent_version IS NULL) OR (consent_at IS NOT NULL AND consent_version IS NOT NULL)),
  CHECK ((stage IN ('hired', 'rejected', 'withdrawn') AND closed_at IS NOT NULL) OR (stage IN ('applied', 'screen', 'interview', 'offer') AND closed_at IS NULL)),
  CHECK (stage NOT IN ('rejected', 'withdrawn') OR stage_before_close IS NOT NULL),
  CHECK ((stage = 'rejected' AND reject_reason IS NOT NULL) OR (stage <> 'rejected' AND reject_reason IS NULL))
);

-- A scheduled screen or interview on an application.
-- App rule (section 7): 1 to 4 active interviewers, one pending scorecard each.
-- App rule (R14): anonymization clears location.
CREATE TABLE interviews (
  id TEXT PRIMARY KEY,
  application_id TEXT NOT NULL REFERENCES applications(id),
  kind TEXT NOT NULL CHECK (kind IN ('screen', 'interview')),
  starts_at TIMESTAMP NOT NULL,
  duration_minutes INTEGER CHECK (duration_minutes BETWEEN 15 AND 240),
  location TEXT CHECK (LENGTH(location) <= 200), -- a room, a phone number or a video link; required when scheduling
  created_by TEXT REFERENCES people(id), -- who scheduled it
  created_at TIMESTAMP NOT NULL,
  cancelled_at TIMESTAMP
);

-- One interviewer feedback form for one interview.
-- App rule (R10): only the assigned interviewer submits, once, after starts_at, with at least one rating and takeaways of 20 or more characters.
-- App rule (R14): anonymization deletes takeaways.
CREATE TABLE scorecards (
  id TEXT PRIMARY KEY,
  interview_id TEXT NOT NULL REFERENCES interviews(id),
  interviewer_id TEXT NOT NULL REFERENCES people(id),
  status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'submitted', 'cancelled')),
  takeaways TEXT CHECK (LENGTH(takeaways) BETWEEN 20 AND 3000),
  recommendation TEXT CHECK (recommendation IN ('definitely_not', 'no', 'yes', 'strong_yes', 'no_decision')), -- no default; no_decision is an explicit choice
  submitted_at TIMESTAMP,
  reminded_at TIMESTAMP, -- set by the job 24 hours after the interview started
  UNIQUE (interview_id, interviewer_id),
  CHECK ((status = 'submitted' AND recommendation IS NOT NULL AND submitted_at IS NOT NULL) OR (status <> 'submitted' AND submitted_at IS NULL))
);

-- One attribute rating on a scorecard.
CREATE TABLE attribute_ratings (
  scorecard_id TEXT NOT NULL REFERENCES scorecards(id),
  attribute_id TEXT NOT NULL REFERENCES role_attributes(id),
  rating INTEGER CHECK (rating BETWEEN 1 AND 4), -- NULL means Not assessed; 1 Weak, 2 Mixed, 3 Good, 4 Strong
  PRIMARY KEY (scorecard_id, attribute_id)
);

-- An internal comment on an application. Admins and the hiring manager only (R12).
CREATE TABLE notes (
  id TEXT PRIMARY KEY,
  application_id TEXT NOT NULL REFERENCES applications(id),
  author_id TEXT NOT NULL REFERENCES people(id),
  text TEXT NOT NULL CHECK (LENGTH(text) BETWEEN 1 AND 2000),
  created_at TIMESTAMP NOT NULL
);

-- One line of the activity log. Never holds candidate personal data.
-- App rule (R18): events are never edited, and only removed by Delete now (R16).
CREATE TABLE events (
  id TEXT PRIMARY KEY,
  application_id TEXT REFERENCES applications(id), -- NULL for candidate_deleted, role and settings events
  actor_id TEXT REFERENCES people(id), -- NULL for the candidate and the system
  type TEXT NOT NULL CHECK (type IN ('applied', 'added', 'stage_changed', 'rejected', 'withdrawn', 'reopened', 'hired', 'interview_scheduled', 'interview_cancelled', 'scorecard_submitted', 'note_added', 'anonymized', 'candidate_deleted', 'role_created', 'role_changed', 'settings_changed')),
  data TEXT, -- JSON text: from/to stage, reason, counts
  created_at TIMESTAMP NOT NULL
);

-- One email in the outbox, written before it is sent.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  kind TEXT NOT NULL, -- the trigger from section 10; the spec gives no fixed list of values
  to_email TEXT NOT NULL,
  person_id TEXT REFERENCES people(id), -- NULL for candidates
  application_id TEXT REFERENCES applications(id),
  subject TEXT NOT NULL,
  body TEXT NOT NULL, -- plain text
  status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'sent', 'logged', 'failed')),
  error TEXT,
  attempts INTEGER NOT NULL DEFAULT 0 CHECK (attempts >= 0), -- each send attempt adds 1; retries stop at 5
  created_at TIMESTAMP NOT NULL,
  sent_at TIMESTAMP
);

-- One accepted careers-form submission, for the rate limit (R5). Rows older than a day are deleted.
CREATE TABLE apply_attempts (
  id TEXT PRIMARY KEY, -- row id; the spec lists only ip_hash and created_at
  ip_hash TEXT NOT NULL, -- HMAC of the IP address with a server secret; the IP itself is never stored
  created_at TIMESTAMP NOT NULL
);
CREATE INDEX apply_attempts_ip_idx ON apply_attempts (ip_hash, created_at);
```

## Seed data

Loads the settings row, 7 people, 3 open roles with their 11 attributes, 9 candidates and 9 applications, 4 interviews, 7 scorecards (2 pending, 5 submitted), Ben Cho's 4 ratings on Sora Ito and Maya's note on Mei Chen, with T fixed at Tue 13 Oct 2026, EDT times converted to UTC and dates without a time set to 12:00 UTC. Placeholders (one fixed value per field, saying the spec leaves it to the builder): the privacy notice, role descriptions, the answer on the 4 careers-page applications, interview locations and the takeaways on the 4 submitted scorecards other than Ben Cho on Sora Ito; team emails (the spec gives none) and withdraw tokens (not random; generate real ones). Placeholder dates, which no worked example depends on: role opened_at (the date of the earliest seeded application for the role), stage_changed_at for Leo, Sora and Ari (their applied date) and Taylor (after the T-8 scorecards), interview created_at (the applied date), scorecard submitted_at (23:00 UTC on the interview day) and the note created_at (the applied date). Left empty because the spec does not give them: interview duration and created_by, and ratings on the 4 submitted scorecards other than Ben Cho on Sora Ito. Events are not seeded, because the spec does not seed them; no notifications or apply attempts either.

## Load it

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

## Design decisions

### One application per candidate per role

Section 5 and R3 allow one application per candidate per role, so applications has UNIQUE (candidate_id, role_id); applying again creates nothing. Candidates are matched by lowercased email, unique among candidates that are not anonymized, which is a partial unique index so anonymized rows with a cleared email never collide.

### The stage decides which close fields are set

Section 6 sets closed_at on hire, reject and withdraw and clears it on reopen, and Reject requires a reason that Reopen clears. Table checks make closed_at present exactly in the three final stages, the reject reason present exactly while rejected, and stage_before_close present for rejected and withdrawn. Moving one stage at a time (R6) and the Offer gate (R7) are cross-row rules left to the app.

### Ratings are their own table, and no score is stored

Each scorecard rates the role's 3 to 6 attributes 1 to 4 or Not assessed, so attribute_ratings is keyed by scorecard and attribute with a nullable rating (NULL means Not assessed). Section 7 says the app never combines ratings into a score, so there is no total or average column. An attribute that has ratings can be renamed but not removed, which the build test found was unspecified. (This point comes from a gap the blueprint's build test found.)

### Anonymization clears fields, so some required fields are nullable

R14 clears a candidate's email, phone and link, an application's answer and close note, interview locations and scorecard takeaways. Those columns are nullable with length checks, and the form rules (answer required on the careers form, location required when scheduling, takeaways required to submit) stay in the app. The build test found applications had no field to mark this, and anonymized_at was added. (This point comes from a gap the blueprint's build test found.)

### A submitted scorecard always has a recommendation

Section 7 makes the recommendation required to submit with no default, and No decision is an explicit value. A table check requires a recommendation and submitted_at whenever status is submitted, and no submitted_at otherwise. One scorecard per interviewer per interview is UNIQUE (interview_id, interviewer_id).

### Role titles are unique only among roles that are not closed

Section 5 makes a title unique ignoring case among roles that are not closed, so a closed Product Designer role does not block a new one. A partial unique index on LOWER(title) WHERE status <> 'closed' does exactly that. An open role also needs a hiring manager and an opened_at, which a table check enforces.

### The digest stores a timestamp, the outbox counts attempts

The build test found that the digest stored only the date of its last run, while listing applications received since the previous digest needs the time, and that retries had nothing to count. settings.last_digest_at is a timestamp and notifications.attempts counts send attempts, with retries stopping at 5. (This point comes from a gap the blueprint's build test found.)

## Example queries

### Board: open applications by role and stage

```sql
SELECT r.title AS role, a.stage, COUNT(*) AS applications FROM applications a JOIN roles r ON r.id = a.role_id WHERE a.stage IN ('applied', 'screen', 'interview', 'offer', 'hired') GROUP BY r.title, a.stage ORDER BY r.title, CASE a.stage WHEN 'applied' THEN 1 WHEN 'screen' THEN 2 WHEN 'interview' THEN 3 WHEN 'offer' THEN 4 ELSE 5 END;
```

On the seed data: 7 rows; Account Executive has 1 each in applied, interview and offer.

### Scorecard summary per application

```sql
SELECT c.name AS candidate, SUM(CASE WHEN s.status = 'submitted' THEN 1 ELSE 0 END) AS submitted, COUNT(*) AS scorecards, SUM(CASE WHEN s.recommendation = 'strong_yes' THEN 1 ELSE 0 END) AS strong_yes, SUM(CASE WHEN s.recommendation = 'yes' THEN 1 ELSE 0 END) AS yes, SUM(CASE WHEN s.recommendation = 'no' THEN 1 ELSE 0 END) AS no, SUM(CASE WHEN s.recommendation = 'definitely_not' THEN 1 ELSE 0 END) AS definitely_not, SUM(CASE WHEN s.recommendation = 'no_decision' THEN 1 ELSE 0 END) AS no_decision FROM scorecards s JOIN interviews i ON i.id = s.interview_id JOIN applications a ON a.id = i.application_id JOIN candidates c ON c.id = a.candidate_id WHERE s.status <> 'cancelled' GROUP BY c.name ORDER BY c.name;
```

On the seed data: 4 rows; Sora Ito has 1 of 2 submitted (Yes 1), Ari Diaz 2 of 2 (Strong yes 1, Yes 1).

### Pending scorecards that block Offer (R7)

```sql
SELECT c.name AS candidate, p.name AS pending_interviewer FROM applications a JOIN candidates c ON c.id = a.candidate_id JOIN interviews i ON i.application_id = a.id AND i.cancelled_at IS NULL JOIN scorecards s ON s.interview_id = i.id AND s.status = 'pending' JOIN people p ON p.id = s.interviewer_id WHERE a.stage = 'interview' ORDER BY c.name, p.name;
```

On the seed data: 1 row, Sora Ito with Sam Okafor pending, as in the worked example.

### Ratings on one scorecard, in attribute order

```sql
SELECT ra.name AS attribute, CASE ar.rating WHEN 1 THEN '1 Weak' WHEN 2 THEN '2 Mixed' WHEN 3 THEN '3 Good' WHEN 4 THEN '4 Strong' ELSE 'Not assessed' END AS rating FROM attribute_ratings ar JOIN role_attributes ra ON ra.id = ar.attribute_id WHERE ar.scorecard_id = 's_sora_ben' ORDER BY ra.position;
```

On the seed data: 4 rows for Ben Cho on Sora Ito, from Discovery questions (3 Good) to Coachability (4 Strong).

### Closed applications due for anonymization (R14)

```sql
SELECT c.name AS candidate, r.title AS role, a.stage, a.closed_at FROM applications a JOIN candidates c ON c.id = a.candidate_id JOIN roles r ON r.id = a.role_id WHERE a.stage IN ('rejected', 'withdrawn') AND a.anonymized_at IS NULL AND a.closed_at < '2026-04-16 12:00:00' ORDER BY a.closed_at;
```

On the seed data at T with retention 180 days: 1 row, Noor Haddad (Product Designer, rejected, closed 2026-03-27).

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