-- 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);