-- Performance Reviews database schema -- Source: https://personalsoftwarefactory.com/blueprints/performance-reviews (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. -- Company settings, one row per setting (company name, time zone, sign-in domain, development clock offset). CREATE TABLE settings ( key TEXT PRIMARY KEY, value TEXT NOT NULL ); -- Someone in the company. manager_id is empty for the top of the company. CREATE TABLE people ( id TEXT PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE CHECK (email = LOWER(email)), -- stored lowercase title TEXT, team TEXT, -- calibration groups ratings by the current team role TEXT NOT NULL DEFAULT 'member' CHECK (role IN ('admin', 'member')), manager_id TEXT REFERENCES people(id), start_date DATE NOT NULL, -- compared with the cycle start_date_cutoff at launch (R1) active BOOLEAN NOT NULL DEFAULT TRUE, pronouns TEXT NOT NULL CHECK (pronouns IN ('he', 'she', 'they')), -- for messages such as: Leo has not submitted his self review yet CHECK (manager_id IS NULL OR manager_id <> id) ); -- A review form. A template used by a launched cycle is read-only; it is duplicated to change it. CREATE TABLE templates ( id TEXT PRIMARY KEY, name TEXT NOT NULL ); -- One question of a template, in order. Question ids are unique within a template. -- App rule (section 5): every template has the question with id overall (rating, manager, required). CREATE TABLE template_questions ( template_id TEXT NOT NULL REFERENCES templates(id), id TEXT NOT NULL, -- stable within the template; answers refer to it position INTEGER NOT NULL, -- order in the list text TEXT NOT NULL, -- {name} is replaced with the employee first name kind TEXT NOT NULL CHECK (kind IN ('text', 'rating')), audience TEXT NOT NULL CHECK (audience IN ('self', 'manager', 'both', 'peer')), required BOOLEAN NOT NULL, PRIMARY KEY (template_id, id), CHECK (id <> 'overall' OR (kind = 'rating' AND audience = 'manager' AND required = TRUE)) ); -- A review cycle. Due dates end at 23:59 in the company time zone. -- App rule (section 7): only a draft cycle can be edited; launch is refused when nobody is eligible or an eligible person has an inactive manager. CREATE TABLE cycles ( id TEXT PRIMARY KEY, name TEXT NOT NULL, template_id TEXT NOT NULL REFERENCES templates(id), status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'active', 'closed')), start_date_cutoff DATE, -- people who started on or before it get a review self_due DATE, peer_due DATE, manager_due DATE, release_on DATE, share_peer_feedback BOOLEAN NOT NULL, peer_min_for_sharing INTEGER NOT NULL DEFAULT 2, launched_at TIMESTAMP, closed_at TIMESTAMP, CHECK (status = 'draft' OR (start_date_cutoff IS NOT NULL AND self_due IS NOT NULL AND peer_due IS NOT NULL AND manager_due IS NOT NULL AND release_on IS NOT NULL AND launched_at IS NOT NULL)), CHECK (self_due < peer_due AND peer_due <= manager_due AND manager_due < release_on), -- launch order (section 7) CHECK (status <> 'closed' OR closed_at IS NOT NULL) ); CREATE UNIQUE INDEX cycles_one_active ON cycles (status) WHERE status = 'active'; -- only one cycle can be active -- One employee in one cycle. The manager is fixed at launch. -- App rule (R2): who sees which part follows the table in section 6, on every request. -- App rule (R4): the manager review can be submitted only after the self review is submitted or self_due has passed. -- App rule (R8): nothing changes after acknowledgement. CREATE TABLE reviews ( id TEXT PRIMARY KEY, cycle_id TEXT NOT NULL REFERENCES cycles(id), employee_id TEXT NOT NULL REFERENCES people(id), manager_id TEXT NOT NULL REFERENCES people(id), -- fixed at launch; an admin can reassign it (section 13) self_status TEXT NOT NULL DEFAULT 'not_started' CHECK (self_status IN ('not_started', 'draft', 'submitted')), manager_status TEXT NOT NULL DEFAULT 'not_started' CHECK (manager_status IN ('not_started', 'draft', 'submitted')), self_submitted_at TIMESTAMP, manager_submitted_at TIMESTAMP, overall_rating INTEGER CHECK (overall_rating BETWEEN 1 AND 5), -- copied from the overall answer when the manager submits calibrated_rating INTEGER CHECK (calibrated_rating BETWEEN 1 AND 5), -- the final rating when set calibration_reason TEXT CHECK (LENGTH(calibration_reason) BETWEEN 10 AND 500), -- never shown to the employee (R6) released_at TIMESTAMP, acknowledged_at TIMESTAMP, acknowledgement_comment TEXT CHECK (LENGTH(acknowledgement_comment) BETWEEN 1 AND 1000), -- an empty comment is stored as NULL UNIQUE (cycle_id, employee_id), CHECK (employee_id <> manager_id), CHECK (self_status <> 'submitted' OR self_submitted_at IS NOT NULL), CHECK ((manager_status = 'submitted' AND manager_submitted_at IS NOT NULL AND overall_rating IS NOT NULL) OR (manager_status <> 'submitted' AND overall_rating IS NULL)), CHECK ((calibrated_rating IS NULL AND calibration_reason IS NULL) OR (calibrated_rating IS NOT NULL AND calibration_reason IS NOT NULL AND manager_status = 'submitted')), CHECK (released_at IS NULL OR manager_status = 'submitted'), -- release needs a submitted manager section CHECK (acknowledged_at IS NULL OR released_at IS NOT NULL), CHECK (acknowledgement_comment IS NULL OR acknowledged_at IS NOT NULL) ); -- One answer to one question in one section of a review, draft or submitted. -- App rule (R3): on submit, required text answers are 20 to 4,000 characters after trimming and ratings 1 to 5. CREATE TABLE answers ( id TEXT PRIMARY KEY, review_id TEXT NOT NULL REFERENCES reviews(id), author_id TEXT NOT NULL REFERENCES people(id), section TEXT NOT NULL CHECK (section IN ('self', 'manager', 'peer')), question_id TEXT NOT NULL, -- a template_questions id in the cycle template text TEXT CHECK (LENGTH(text) <= 4000), -- the maximum applies to drafts too rating INTEGER CHECK (rating BETWEEN 1 AND 5), updated_at TIMESTAMP NOT NULL, UNIQUE (review_id, author_id, section, question_id), CHECK (text IS NULL OR rating IS NULL) -- text or rating ); -- A peer the employee proposed to give feedback on their review. -- App rule (section 7): 1 to 3 peers per review in total, never the employee or their manager; a decision cannot be changed. CREATE TABLE peer_requests ( id TEXT PRIMARY KEY, review_id TEXT NOT NULL REFERENCES reviews(id), peer_id TEXT NOT NULL REFERENCES people(id), status TEXT NOT NULL DEFAULT 'proposed' CHECK (status IN ('proposed', 'approved', 'declined', 'submitted', 'peer_declined', 'cancelled')), decided_by TEXT REFERENCES people(id), -- the manager fixed on the review reason TEXT CHECK (LENGTH(reason) BETWEEN 1 AND 500), submitted_at TIMESTAMP, UNIQUE (review_id, peer_id), -- a declined peer cannot be proposed again CHECK (status NOT IN ('declined', 'peer_declined', 'cancelled') OR reason IS NOT NULL), CHECK (status NOT IN ('approved', 'declined', 'submitted', 'peer_declined') OR decided_by IS NOT NULL), CHECK ((status = 'submitted' AND submitted_at IS NOT NULL) OR (status <> 'submitted' AND submitted_at IS NULL)) ); -- One line of the append-only activity log. -- App rule (R10): events are never edited or deleted, except by the development-only reset to seed data. CREATE TABLE events ( id TEXT PRIMARY KEY, at TIMESTAMP NOT NULL, actor TEXT REFERENCES people(id), -- NULL for the system type TEXT NOT NULL, -- the spec gives no fixed list data TEXT -- JSON text ); -- One email in the outbox, listed newest first by created_at. CREATE TABLE notifications ( id TEXT PRIMARY KEY, created_at TIMESTAMP NOT NULL, kind TEXT NOT NULL, -- the trigger from section 10; the spec gives no fixed list to_email TEXT NOT NULL, subject TEXT NOT NULL, body TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'sent', 'failed', 'logged')), error TEXT ); -- A reminder that has been sent, so each one goes out at most once (R9). CREATE TABLE reminders_sent ( cycle_id TEXT NOT NULL REFERENCES cycles(id), step TEXT NOT NULL CHECK (step IN ('self', 'peer', 'manager')), due_date DATE NOT NULL, reminder_day TEXT NOT NULL CHECK (reminder_day IN ('three_days', 'due_day')), -- the spec field when, renamed (reserved word) person_id TEXT NOT NULL REFERENCES people(id), PRIMARY KEY (cycle_id, step, due_date, reminder_day, person_id) );